JobsMgr.js
5.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**
* Project : AMDA-NG4
* Name : JobsMgr.js
* @class amdaDesktop.JobsMgr
* @extends Ext.AbstractManager
* @brief Manages Jobs In Progress
* @author elena
* @version $Id: JobsMgr.js 2759 2015-02-19 12:32:31Z elena $
* @todo
*******************************************************************************
* FT Id : Date : Name - Description
*******************************************************************************
* : :28/01/2011:
*/
Ext.define('amdaDesktop.JobsMgr', {
extend: 'Ext.AbstractManager',
singleton: true,
first : true,
jobsInProgress : 0,
jobsFinished : 0,
jobsError : 0,
updateStatus : null,
interval : 60000, // //msec 60000
jobTree : null,
//TODO first => at login !!!
getStatus : function(){
AmdaAction.getJobs(function(res,e){
//TODO Errors processing
if (e.status) {
if (res.success) {
// Update from Server Jobs Running and Finished
if (res.nFinished > 0 ) {
Ext.each(res.jobsFinished, function(item, index, all){
if (item.status != 'old') {
switch (item.jobType) {
case 'condition' : var type = 'Data Mining '; break;
case 'request' : var type = 'Plot '; break;
case 'download' : var type = 'Download '; break;
case 'statistics' : var type = 'Statistics '; break;
default: var type = 'unknown';
}
var message = Ext.Date.format(new Date(), 'd-m-Y H:i:s: ') + ': '+ type + ' '+item.name + ' completed';
myDesktopApp.getLoadedModule(myDesktopApp.dynamicModules.explorer.id, true, function (module) {
module.addLogMessage(message);
});
}
});
}
if (amdaDesktop.JobsMgr.first && (res.nInProgress > 0 || res.nFinished > 0)) {
myDesktopApp.infoMsg('You have '+ res.nFinished + ' new finished jobs and ' + res.nInProgress + ' jobs in progress');
}
amdaDesktop.JobsMgr.jobsInProgress = res.nInProgress;
amdaDesktop.JobsMgr.jobsFinished = res.nFinished;
amdaDesktop.JobsMgr.jobsError = res.nError;
if (res.nInProgress == 0 && amdaDesktop.JobsMgr.updateStatus)
{
Ext.TaskManager.stop(amdaDesktop.JobsMgr.updateStatus);
amdaDesktop.JobsMgr.updateStatus = null;
}
if (res.nInProgress > 0 && !amdaDesktop.JobsMgr.updateStatus)
{
amdaDesktop.JobsMgr.updateStatus =
Ext.TaskManager.start({
run : amdaDesktop.JobsMgr.getStatus,
interval : amdaDesktop.JobsMgr.interval
});
}
if (res.nFinished > 0 && !amdaDesktop.JobsMgr.first) {
if (!amdaDesktop.JobsMgr.jobTree)
amdaDesktop.JobsMgr.jobTree = Ext.getCmp(amdaUI.ExplorerUI.JOB_TAB.TREE_ID);
Ext.each(res.jobsFinished, function(job) {
switch (job.jobType) {
case 'condition':
//TODO get root nodes depending on conditions
var resRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.RES_ROOT_NODE.CONDITION, true);
var jobRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.JOB_ROOT_NODE.CONDITION, true);
break;
case 'request' :
var resRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.RES_ROOT_NODE.PLOT, true);
var jobRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.JOB_ROOT_NODE.PLOT, true);
break;
case 'download' :
var resRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.RES_ROOT_NODE.DOWNLOAD, true);
var jobRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.JOB_ROOT_NODE.DOWNLOAD, true);
break;
case 'statistics' :
var resRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.RES_ROOT_NODE.STATISTICS, true);
var jobRootNode =
amdaDesktop.JobsMgr.jobTree.getRootNode().findChild('id',amdaModel.BkgJobNode.JOB_ROOT_NODE.STATISTICS, true);
break;
default :
}
//TODO check: job sub tree is always expanded - after the first job is launched - there cannot be too many unfinished jobs on login
// so callback is not needed
if (!resRootNode.parentNode.isExpanded()) resRootNode.parentNode.expand(false);
if (!jobRootNode.parentNode.isExpanded()) jobRootNode.parentNode.expand(false);
if (!jobRootNode.isExpanded()) jobRootNode.expand(false);
//AKKA - use processid to find job
var nodeToMove = jobRootNode.findChild('id', job.id, false);
nodeToMove.set('status',job.status);
//TODO check if really job.status
nodeToMove.set('iconCls',job.status);
jobRootNode.removeChild(nodeToMove);
if (!resRootNode.isExpanded()) {
resRootNode.expand(false, function(){
if (!resRootNode.findChild('id', nodeToMove.get('processId')))
resRootNode.appendChild(nodeToMove);
});
}
else resRootNode.appendChild(nodeToMove);
});
}
}
}
amdaDesktop.JobsMgr.first = false;
});
}
})