Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Yaxel Perez
jio
Commits
298da338
Commit
298da338
authored
Oct 11, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
job features event management changed to be more maintainable
Job queues are now saved in workspace at different moment
parent
ad9c7aad
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
254 additions
and
175 deletions
+254
-175
src/jio/core/JIO.js
src/jio/core/JIO.js
+1
-1
src/jio/features/jobChecker.js
src/jio/features/jobChecker.js
+17
-9
src/jio/features/jobExecuter.js
src/jio/features/jobExecuter.js
+49
-26
src/jio/features/jobMaker.js
src/jio/features/jobMaker.js
+41
-34
src/jio/features/jobQueue.js
src/jio/features/jobQueue.js
+59
-45
src/jio/features/jobRecovery.js
src/jio/features/jobRecovery.js
+8
-5
src/jio/features/jobReference.js
src/jio/features/jobReference.js
+3
-3
src/jio/features/jobRetry.js
src/jio/features/jobRetry.js
+21
-15
src/jio/features/jobTimeout.js
src/jio/features/jobTimeout.js
+33
-26
test/jio/tests.js
test/jio/tests.js
+22
-11
No files found.
src/jio/core/JIO.js
View file @
298da338
...
@@ -21,10 +21,10 @@ function JIO(storage_spec, options) {
...
@@ -21,10 +21,10 @@ function JIO(storage_spec, options) {
enableJobMaker
(
this
,
shared
,
options
);
enableJobMaker
(
this
,
shared
,
options
);
enableJobReference
(
this
,
shared
,
options
);
enableJobReference
(
this
,
shared
,
options
);
enableJobRetry
(
this
,
shared
,
options
);
enableJobRetry
(
this
,
shared
,
options
);
enableJobTimeout
(
this
,
shared
,
options
);
enableJobChecker
(
this
,
shared
,
options
);
enableJobChecker
(
this
,
shared
,
options
);
enableJobQueue
(
this
,
shared
,
options
);
enableJobQueue
(
this
,
shared
,
options
);
enableJobRecovery
(
this
,
shared
,
options
);
enableJobRecovery
(
this
,
shared
,
options
);
enableJobTimeout
(
this
,
shared
,
options
);
enableJobExecuter
(
this
,
shared
,
options
);
enableJobExecuter
(
this
,
shared
,
options
);
shared
.
emit
(
'
load
'
);
shared
.
emit
(
'
load
'
);
...
...
src/jio/features/jobChecker.js
View file @
298da338
...
@@ -13,7 +13,9 @@ function enableJobChecker(jio, shared, options) {
...
@@ -13,7 +13,9 @@ function enableJobChecker(jio, shared, options) {
// creates
// creates
// - shared.job_rules Array
// - shared.job_rules Array
// uses 'job' event
// uses 'job:new' event
// emits 'job:modified', 'job:start', 'job:resolved',
// 'job:end', 'job:reject' events
var
i
;
var
i
;
...
@@ -22,33 +24,39 @@ function enableJobChecker(jio, shared, options) {
...
@@ -22,33 +24,39 @@ function enableJobChecker(jio, shared, options) {
shared
.
job_rule_actions
=
{
shared
.
job_rule_actions
=
{
wait
:
function
(
original_job
,
new_job
)
{
wait
:
function
(
original_job
,
new_job
)
{
original_job
.
promise
.
always
(
function
()
{
original_job
.
promise
.
always
(
function
()
{
shared
.
emit
(
'
job
'
,
new_job
);
new_job
.
state
=
'
ready
'
;
new_job
.
modified
=
new
Date
();
shared
.
emit
(
'
job:modified
'
,
new_job
);
shared
.
emit
(
'
job:start
'
,
new_job
);
});
});
new_job
.
state
=
'
waiting
'
;
new_job
.
state
=
'
waiting
'
;
new_job
.
modified
=
new
Date
();
new_job
.
modified
=
new
Date
();
shared
.
emit
(
'
job:modified
'
,
new_job
);
},
},
update
:
function
(
original_job
,
new_job
)
{
update
:
function
(
original_job
,
new_job
)
{
if
(
!
new_job
.
solver
)
{
if
(
!
new_job
.
solver
)
{
// promise associated to the job
// promise associated to the job
new_job
.
state
=
'
done
'
;
new_job
.
state
=
'
done
'
;
shared
.
emit
(
'
jobDone
'
,
new_job
);
shared
.
emit
(
'
job:resolved
'
,
new_job
,
[]);
// XXX why resolve?
shared
.
emit
(
'
job:end
'
,
new_job
);
}
else
{
}
else
{
if
(
!
original_job
.
solver
)
{
if
(
!
original_job
.
solver
)
{
original_job
.
solver
=
new_job
.
solver
;
original_job
.
solver
=
new_job
.
solver
;
}
else
{
}
else
{
original_job
.
promise
.
then
(
original_job
.
promise
.
then
(
new_job
.
command
.
resolve
,
new_job
.
command
.
resolve
,
new_job
.
command
.
reject
new_job
.
command
.
reject
,
new_job
.
command
.
notify
);
);
}
}
}
}
new_job
.
state
=
'
running
'
;
new_job
.
state
=
'
running
'
;
new_job
.
modified
=
new
Date
();
new_job
.
modified
=
new
Date
();
shared
.
emit
(
'
job:modified
'
,
new_job
);
},
},
deny
:
function
(
original_job
,
new_job
)
{
deny
:
function
(
original_job
,
new_job
)
{
new_job
.
state
=
'
fail
'
;
new_job
.
state
=
"
running
"
;
new_job
.
modified
=
new
Date
();
shared
.
emit
(
'
job:reject
'
,
new_job
,
[
restCommandRejecter
(
new_job
,
[
'
precondition_failed
'
,
'
precondition_failed
'
,
'
command denied
'
,
'
command denied
'
,
'
Command rejected by the job checker.
'
'
Command rejected by the job checker.
'
...
@@ -170,7 +178,7 @@ function enableJobChecker(jio, shared, options) {
...
@@ -170,7 +178,7 @@ function enableJobChecker(jio, shared, options) {
}
}
}
else
{
}
else
{
// browsing jobs
// browsing jobs
for
(
j
=
0
;
j
<
shared
.
jobs
.
length
;
j
+
=
1
)
{
for
(
j
=
shared
.
jobs
.
length
-
1
;
j
>=
0
;
j
-
=
1
)
{
if
(
shared
.
jobs
[
j
]
!==
job
)
{
if
(
shared
.
jobs
[
j
]
!==
job
)
{
if
(
if
(
jobsRespectConditions
(
jobsRespectConditions
(
...
@@ -235,7 +243,7 @@ function enableJobChecker(jio, shared, options) {
...
@@ -235,7 +243,7 @@ function enableJobChecker(jio, shared, options) {
}
}
}
}
shared
.
on
(
'
job
'
,
checkJob
);
shared
.
on
(
'
job
:new
'
,
checkJob
);
}
}
...
...
src/jio/features/jobExecuter.js
View file @
298da338
...
@@ -4,19 +4,28 @@
...
@@ -4,19 +4,28 @@
function
enableJobExecuter
(
jio
,
shared
)
{
// , options) {
function
enableJobExecuter
(
jio
,
shared
)
{
// , options) {
// uses 'job
', 'jobDone', 'jobFail' and 'jobNotify
' events
// uses 'job
:new
' events
//
emits 'jobRun' and 'jobEnd' events
//
uses actions 'job:resolve', 'job:reject' and 'job:notify'
// listeners
// emits 'job:modified', 'job:started', 'job:resolved',
// 'job:rejected', 'job:notified' and 'job:end' events
// emits action 'job:start'
function
startJobIfReady
(
job
)
{
if
(
job
.
state
===
'
ready
'
)
{
shared
.
emit
(
'
job:start
'
,
job
);
}
}
shared
.
on
(
'
job
'
,
function
(
param
)
{
function
executeJobIfReady
(
param
)
{
var
storage
;
var
storage
;
if
(
param
.
state
===
'
ready
'
)
{
if
(
param
.
state
===
'
ready
'
)
{
param
.
tried
+=
1
;
param
.
tried
+=
1
;
param
.
started
=
new
Date
();
param
.
started
=
new
Date
();
param
.
state
=
'
running
'
;
param
.
state
=
'
running
'
;
param
.
modified
=
new
Date
();
param
.
modified
=
new
Date
();
shared
.
emit
(
'
jobRun
'
,
param
);
shared
.
emit
(
'
job:modified
'
,
param
);
shared
.
emit
(
'
job:started
'
,
param
);
try
{
try
{
storage
=
createStorage
(
deepClone
(
param
.
storage_spec
));
storage
=
createStorage
(
deepClone
(
param
.
storage_spec
));
}
catch
(
e
)
{
}
catch
(
e
)
{
...
@@ -44,33 +53,47 @@ function enableJobExecuter(jio, shared) { // , options) {
...
@@ -44,33 +53,47 @@ function enableJobExecuter(jio, shared) { // , options) {
);
);
});
});
}
}
}
);
}
shared
.
on
(
'
jobDone
'
,
function
(
param
,
args
)
{
function
endAndResolveIfRunning
(
job
,
args
)
{
if
(
param
.
state
===
'
running
'
)
{
if
(
job
.
state
===
'
running
'
)
{
param
.
state
=
'
done
'
;
job
.
state
=
'
done
'
;
param
.
modified
=
new
Date
();
job
.
modified
=
new
Date
();
shared
.
emit
(
'
job
End
'
,
param
);
shared
.
emit
(
'
job
:modified
'
,
job
);
if
(
param
.
solver
)
{
if
(
job
.
solver
)
{
restCommandResolver
(
param
,
args
);
restCommandResolver
(
job
,
args
);
}
}
shared
.
emit
(
'
job:resolved
'
,
job
,
args
);
shared
.
emit
(
'
job:end
'
,
job
);
}
}
}
);
}
shared
.
on
(
'
jobFail
'
,
function
(
param
,
args
)
{
function
endAndRejectIfRunning
(
job
,
args
)
{
if
(
param
.
state
===
'
running
'
)
{
if
(
job
.
state
===
'
running
'
)
{
param
.
state
=
'
fail
'
;
job
.
state
=
'
fail
'
;
param
.
modified
=
new
Date
();
job
.
modified
=
new
Date
();
shared
.
emit
(
'
job
End
'
,
param
);
shared
.
emit
(
'
job
:modified
'
,
job
);
if
(
param
.
solver
)
{
if
(
job
.
solver
)
{
restCommandRejecter
(
param
,
args
);
restCommandRejecter
(
job
,
args
);
}
}
shared
.
emit
(
'
job:rejected
'
,
job
,
args
);
shared
.
emit
(
'
job:end
'
,
job
);
}
}
}
);
}
shared
.
on
(
'
jobNotify
'
,
function
(
param
,
args
)
{
function
notifyJobIfRunning
(
job
,
args
)
{
if
(
param
.
state
===
'
running
'
&&
param
.
solver
)
{
if
(
job
.
state
===
'
running
'
&&
job
.
solver
)
{
param
.
solver
.
notify
(
args
[
0
]);
job
.
solver
.
notify
(
args
[
0
]);
shared
.
emit
(
'
job:notified
'
,
job
,
args
);
}
}
});
}
// listeners
shared
.
on
(
'
job:new
'
,
startJobIfReady
);
shared
.
on
(
'
job:start
'
,
executeJobIfReady
);
shared
.
on
(
'
job:resolve
'
,
endAndResolveIfRunning
);
shared
.
on
(
'
job:reject
'
,
endAndRejectIfRunning
);
shared
.
on
(
'
job:notify
'
,
notifyJobIfRunning
);
}
}
src/jio/features/jobMaker.js
View file @
298da338
...
@@ -20,10 +20,16 @@ function enableJobMaker(jio, shared, options) {
...
@@ -20,10 +20,16 @@ function enableJobMaker(jio, shared, options) {
// - param.options object
// - param.options object
// - param.command object
// - param.command object
// uses method events
// list of job events:
// add emits 'job' events
// - Job existence -> new, end
// - Job execution -> started, stopped
// - Job resolution -> resolved, rejected, notified, cancelled
// - Job modification -> modified
// the job can emit 'jobDone', 'jobFail' and 'jobNotify'
// emits actions 'job:resolve', 'job:reject' and 'job:notify'
// uses `rest method` events
// emits 'job:new' event
shared
.
job_keys
=
arrayExtend
(
shared
.
job_keys
||
[],
[
shared
.
job_keys
=
arrayExtend
(
shared
.
job_keys
||
[],
[
"
created
"
,
"
created
"
,
...
@@ -36,48 +42,49 @@ function enableJobMaker(jio, shared, options) {
...
@@ -36,48 +42,49 @@ function enableJobMaker(jio, shared, options) {
"
options
"
"
options
"
]);
]);
function
addCommandToJob
(
param
)
{
function
addCommandToJob
(
job
)
{
param
.
command
=
{};
job
.
command
=
{};
param
.
command
.
resolve
=
function
()
{
job
.
command
.
resolve
=
function
()
{
shared
.
emit
(
'
job
Done
'
,
param
,
arguments
);
shared
.
emit
(
'
job
:resolve
'
,
job
,
arguments
);
};
};
param
.
command
.
success
=
param
.
command
.
resolve
;
job
.
command
.
success
=
job
.
command
.
resolve
;
param
.
command
.
reject
=
function
()
{
job
.
command
.
reject
=
function
()
{
shared
.
emit
(
'
job
Fail
'
,
param
,
arguments
);
shared
.
emit
(
'
job
:reject
'
,
job
,
arguments
);
};
};
param
.
command
.
error
=
param
.
command
.
reject
;
job
.
command
.
error
=
job
.
command
.
reject
;
param
.
command
.
notify
=
function
()
{
job
.
command
.
notify
=
function
()
{
shared
.
emit
(
'
job
Notify
'
,
param
,
arguments
);
shared
.
emit
(
'
job
:notify
'
,
job
,
arguments
);
};
};
param
.
command
.
storage
=
function
()
{
job
.
command
.
storage
=
function
()
{
return
shared
.
createRestApi
.
apply
(
null
,
arguments
);
return
shared
.
createRestApi
.
apply
(
null
,
arguments
);
};
};
}
}
function
createJobFromRest
(
param
)
{
if
(
param
.
solver
)
{
// rest parameters are good
shared
.
emit
(
'
job:new
'
,
param
);
}
}
function
initJob
(
job
)
{
job
.
state
=
'
ready
'
;
if
(
typeof
job
.
tried
!==
'
number
'
||
!
isFinite
(
job
.
tried
))
{
job
.
tried
=
0
;
}
if
(
!
job
.
created
)
{
job
.
created
=
new
Date
();
}
addCommandToJob
(
job
);
job
.
modified
=
new
Date
();
}
// listeners
// listeners
shared
.
rest_method_names
.
forEach
(
function
(
method
)
{
shared
.
rest_method_names
.
forEach
(
function
(
method
)
{
shared
.
on
(
method
,
function
(
param
)
{
shared
.
on
(
method
,
createJobFromRest
);
if
(
param
.
solver
)
{
// params are good
shared
.
emit
(
'
job
'
,
param
);
}
});
});
});
shared
.
on
(
'
job
'
,
function
(
param
)
{
shared
.
on
(
'
job:new
'
,
initJob
);
// new or recovered job
param
.
state
=
'
ready
'
;
if
(
typeof
param
.
tried
!==
'
number
'
||
!
isFinite
(
param
.
tried
))
{
param
.
tried
=
0
;
}
if
(
!
param
.
created
)
{
param
.
created
=
new
Date
();
}
if
(
!
param
.
command
)
{
addCommandToJob
(
param
);
}
param
.
modified
=
new
Date
();
});
}
}
src/jio/features/jobQueue.js
View file @
298da338
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayExtend, localStorage, Workspace, uniqueJSONStringify, JobQueue,
/*global arrayExtend, localStorage, Workspace, uniqueJSONStringify, JobQueue,
constants, indexOf */
constants, indexOf
, setTimeout, clearTimeout
*/
function
enableJobQueue
(
jio
,
shared
,
options
)
{
function
enableJobQueue
(
jio
,
shared
,
options
)
{
...
@@ -16,8 +16,56 @@ function enableJobQueue(jio, shared, options) {
...
@@ -16,8 +16,56 @@ function enableJobQueue(jio, shared, options) {
// - shared.workspace Workspace
// - shared.workspace Workspace
// - shared.job_queue JobQueue
// - shared.job_queue JobQueue
// uses 'job', 'jobRun', 'jobStop', 'jobEnd' events
// uses 'job:new', 'job:started', 'job:stopped', 'job:modified',
// emits 'jobEnd' events
// 'job:notified', 'job:end' events
// emits 'job:end' event
function
postJobIfReady
(
param
)
{
if
(
!
param
.
stored
&&
param
.
state
===
'
ready
'
)
{
clearTimeout
(
param
.
queue_ident
);
delete
param
.
queue_ident
;
shared
.
job_queue
.
load
();
shared
.
job_queue
.
post
(
param
);
shared
.
job_queue
.
save
();
param
.
stored
=
true
;
}
}
function
deferredPutJob
(
param
)
{
if
(
param
.
queue_ident
===
undefined
)
{
param
.
queue_ident
=
setTimeout
(
function
()
{
delete
param
.
queue_ident
;
if
(
param
.
stored
)
{
shared
.
job_queue
.
load
();
shared
.
job_queue
.
put
(
param
);
shared
.
job_queue
.
save
();
}
});
}
}
function
removeJob
(
param
)
{
clearTimeout
(
param
.
queue_ident
);
delete
param
.
queue_ident
;
if
(
param
.
stored
)
{
shared
.
job_queue
.
load
();
shared
.
job_queue
.
remove
(
param
.
id
);
shared
.
job_queue
.
save
();
delete
param
.
stored
;
delete
param
.
id
;
}
}
function
initJob
(
param
)
{
if
(
!
param
.
command
.
end
)
{
param
.
command
.
end
=
function
()
{
shared
.
emit
(
'
job:end
'
,
param
);
};
}
}
shared
.
on
(
'
job:new
'
,
initJob
);
if
(
options
.
job_management
!==
false
)
{
if
(
options
.
job_management
!==
false
)
{
...
@@ -39,51 +87,17 @@ function enableJobQueue(jio, shared, options) {
...
@@ -39,51 +87,17 @@ function enableJobQueue(jio, shared, options) {
shared
.
job_keys
shared
.
job_keys
);
);
shared
.
on
(
'
job
'
,
function
(
param
)
{
// Listeners
if
(
indexOf
(
param
.
state
,
[
'
fail
'
,
'
done
'
])
===
-
1
)
{
if
(
!
param
.
stored
)
{
shared
.
job_queue
.
load
();
shared
.
job_queue
.
post
(
param
);
shared
.
job_queue
.
save
();
param
.
stored
=
true
;
}
}
});
[
'
jobRun
'
,
'
jobStop
'
].
forEach
(
function
(
event
)
{
shared
.
on
(
'
job:new
'
,
postJobIfReady
);
shared
.
on
(
event
,
function
(
param
)
{
if
(
param
.
stored
)
{
shared
.
job_queue
.
load
();
if
(
param
.
state
===
'
done
'
||
param
.
state
===
'
fail
'
)
{
if
(
shared
.
job_queue
.
remove
(
param
.
id
))
{
shared
.
job_queue
.
save
();
delete
param
.
storad
;
}
}
else
{
shared
.
job_queue
.
put
(
param
);
shared
.
job_queue
.
save
();
}
}
});
});
shared
.
on
(
'
jobEnd
'
,
function
(
param
)
{
shared
.
on
(
'
job:started
'
,
deferredPutJob
);
if
(
param
.
stored
)
{
shared
.
on
(
'
job:stopped
'
,
deferredPutJob
);
shared
.
job_queue
.
load
();
shared
.
on
(
'
job:modified
'
,
deferredPutJob
);
if
(
shared
.
job_queue
.
remove
(
param
.
id
))
{
shared
.
on
(
'
job:notified
'
,
deferredPutJob
);
shared
.
job_queue
.
save
();
}
}
});
}
shared
.
on
(
'
job:end
'
,
removeJob
);
shared
.
on
(
'
job
'
,
function
(
param
)
{
}
if
(
!
param
.
command
.
end
)
{
param
.
command
.
end
=
function
()
{
shared
.
emit
(
'
jobEnd
'
,
param
);
};
}
});
}
}
src/jio/features/jobRecovery.js
View file @
298da338
...
@@ -9,20 +9,23 @@ function enableJobRecovery(jio, shared, options) {
...
@@ -9,20 +9,23 @@ function enableJobRecovery(jio, shared, options) {
// uses
// uses
// - shared.job_queue JobQueue
// - shared.job_queue JobQueue
// emits 'job:new' event
function
numberOrDefault
(
number
,
default_value
)
{
function
numberOrDefault
(
number
,
default_value
)
{
return
(
typeof
number
===
'
number
'
&&
return
(
typeof
number
===
'
number
'
&&
isFinite
(
number
)
?
number
:
default_value
);
isFinite
(
number
)
?
number
:
default_value
);
}
}
function
recoverJob
(
param
)
{
function
recoverJob
(
param
)
{
shared
.
job_queue
.
load
();
shared
.
job_queue
.
remove
(
param
.
id
);
shared
.
job_queue
.
remove
(
param
.
id
);
delete
param
.
id
;
delete
param
.
id
;
if
(
methodType
(
param
.
method
)
===
'
writer
'
||
if
(
methodType
(
param
.
method
)
===
'
writer
'
&&
param
.
state
===
'
ready
'
||
(
param
.
state
===
'
ready
'
||
param
.
state
===
'
running
'
||
param
.
state
===
'
running
'
||
param
.
state
===
'
waiting
'
)
{
param
.
state
===
'
waiting
'
)
)
{
shared
.
job_queue
.
save
();
shared
.
job_queue
.
save
();
shared
.
emit
(
'
job
'
,
param
);
shared
.
emit
(
'
job
:new
'
,
param
);
}
}
}
}
...
...
src/jio/features/jobReference.js
View file @
298da338
...
@@ -6,17 +6,17 @@ function enableJobReference(jio, shared, options) {
...
@@ -6,17 +6,17 @@ function enableJobReference(jio, shared, options) {
// creates
// creates
// - shared.jobs Object Array
// - shared.jobs Object Array
// uses 'job
', 'jobE
nd' events
// uses 'job
:new' and 'job:e
nd' events
shared
.
jobs
=
[];
shared
.
jobs
=
[];
var
job_references
=
new
ReferenceArray
(
shared
.
jobs
);
var
job_references
=
new
ReferenceArray
(
shared
.
jobs
);
shared
.
on
(
'
job
'
,
function
(
param
)
{
shared
.
on
(
'
job
:new
'
,
function
(
param
)
{
job_references
.
put
(
param
);
job_references
.
put
(
param
);
});
});
shared
.
on
(
'
job
E
nd
'
,
function
(
param
)
{
shared
.
on
(
'
job
:e
nd
'
,
function
(
param
)
{
job_references
.
remove
(
param
);
job_references
.
remove
(
param
);
});
});
}
}
src/jio/features/jobRetry.js
View file @
298da338
...
@@ -27,9 +27,9 @@ function enableJobRetry(jio, shared, options) {
...
@@ -27,9 +27,9 @@ function enableJobRetry(jio, shared, options) {
// - param.options object
// - param.options object
// - param.command object
// - param.command object
// uses 'job
' and 'jobR
etry' events
// uses 'job
:new' and 'job:r
etry' events
// emits
'job', 'jobFail' and 'jobStateChange' events
// emits
action 'job:start' event
//
job can emit 'jobRetry'
//
emits 'job:retry', 'job:reject', 'job:modified' and 'job:stopped' events
shared
.
job_keys
=
arrayExtend
(
shared
.
job_keys
||
[],
[
"
max_retry
"
]);
shared
.
job_keys
=
arrayExtend
(
shared
.
job_keys
||
[],
[
"
max_retry
"
]);
...
@@ -73,9 +73,7 @@ function enableJobRetry(jio, shared, options) {
...
@@ -73,9 +73,7 @@ function enableJobRetry(jio, shared, options) {
2
2
);
);
// listeners
function
initJob
(
param
)
{
shared
.
on
(
'
job
'
,
function
(
param
)
{
if
(
typeof
param
.
max_retry
!==
'
number
'
||
param
.
max_retry
<
0
)
{
if
(
typeof
param
.
max_retry
!==
'
number
'
||
param
.
max_retry
<
0
)
{
param
.
max_retry
=
positiveNumberOrDefault
(
param
.
max_retry
=
positiveNumberOrDefault
(
param
.
options
.
max_retry
,
param
.
options
.
max_retry
,
...
@@ -84,32 +82,40 @@ function enableJobRetry(jio, shared, options) {
...
@@ -84,32 +82,40 @@ function enableJobRetry(jio, shared, options) {
}
}
param
.
command
.
reject
=
function
(
status
)
{
param
.
command
.
reject
=
function
(
status
)
{
if
(
constants
.
http_action
[
status
||
0
]
===
"
retry
"
)
{
if
(
constants
.
http_action
[
status
||
0
]
===
"
retry
"
)
{
shared
.
emit
(
'
job
R
etry
'
,
param
,
arguments
);
shared
.
emit
(
'
job
:r
etry
'
,
param
,
arguments
);
}
else
{
}
else
{
shared
.
emit
(
'
job
Fail
'
,
param
,
arguments
);
shared
.
emit
(
'
job
:reject
'
,
param
,
arguments
);
}
}
};
};
param
.
command
.
retry
=
function
()
{
param
.
command
.
retry
=
function
()
{
shared
.
emit
(
'
job
R
etry
'
,
param
,
arguments
);
shared
.
emit
(
'
job
:r
etry
'
,
param
,
arguments
);
};
};
}
);
}
shared
.
on
(
'
jobRetry
'
,
function
(
param
,
args
)
{
function
retryIfRunning
(
param
,
args
)
{
if
(
param
.
state
===
'
running
'
)
{
if
(
param
.
state
===
'
running
'
)
{
if
(
param
.
max_retry
===
undefined
||
if
(
param
.
max_retry
===
undefined
||
param
.
max_retry
===
null
||
param
.
max_retry
===
null
||
param
.
max_retry
>=
param
.
tried
)
{
param
.
max_retry
>=
param
.
tried
)
{
param
.
state
=
'
waiting
'
;
param
.
state
=
'
waiting
'
;
param
.
modified
=
new
Date
();
param
.
modified
=
new
Date
();
shared
.
emit
(
'
jobStop
'
,
param
);
shared
.
emit
(
'
job:modified
'
,
param
);
shared
.
emit
(
'
job:stopped
'
,
param
);
setTimeout
(
function
()
{
setTimeout
(
function
()
{
param
.
state
=
'
ready
'
;
param
.
state
=
'
ready
'
;
param
.
modified
=
new
Date
();
param
.
modified
=
new
Date
();
shared
.
emit
(
'
job
'
,
param
);
shared
.
emit
(
'
job:modified
'
,
param
);
shared
.
emit
(
'
job:start
'
,
param
);
},
min
(
10000
,
param
.
tried
*
2000
));
},
min
(
10000
,
param
.
tried
*
2000
));
}
else
{
}
else
{
shared
.
emit
(
'
job
Fail
'
,
param
,
args
);
shared
.
emit
(
'
job
:reject
'
,
param
,
args
);
}
}
}
}
});
}
// listeners
shared
.
on
(
'
job:new
'
,
initJob
);
shared
.
on
(
'
job:retry
'
,
retryIfRunning
);
}
}
src/jio/features/jobTimeout.js
View file @
298da338
...
@@ -13,7 +13,9 @@ function enableJobTimeout(jio, shared, options) {
...
@@ -13,7 +13,9 @@ function enableJobTimeout(jio, shared, options) {
// - param.timeout_ident Timeout
// - param.timeout_ident Timeout
// - param.state string 'running'
// - param.state string 'running'
// uses 'job', 'jobDone', 'jobFail', 'jobRetry' and 'jobNotify' events
// uses 'job:new', 'job:stopped', 'job:started',
// 'job:notified' and 'job:end' events
// emits 'job:modified' event
shared
.
job_keys
=
arrayExtend
(
shared
.
job_keys
||
[],
[
"
timeout
"
]);
shared
.
job_keys
=
arrayExtend
(
shared
.
job_keys
||
[],
[
"
timeout
"
]);
...
@@ -38,34 +40,39 @@ function enableJobTimeout(jio, shared, options) {
...
@@ -38,34 +40,39 @@ function enableJobTimeout(jio, shared, options) {
};
};
}
}
// listeners
function
initJob
(
job
)
{
if
(
typeof
job
.
timeout
!==
'
number
'
||
job
.
timeout
<
0
)
{
shared
.
on
(
'
job
'
,
function
(
param
)
{
job
.
timeout
=
positiveNumberOrDefault
(
if
(
typeof
param
.
timeout
!==
'
number
'
||
param
.
timeout
<
0
)
{
job
.
options
.
timeout
,
param
.
timeout
=
positiveNumberOrDefault
(
param
.
options
.
timeout
,
default_timeout
default_timeout
);
);
}
}
param
.
modified
=
new
Date
();
job
.
modified
=
new
Date
();
});
shared
.
emit
(
'
job:modified
'
,
job
);
}
function
clearJobTimeout
(
job
)
{
clearTimeout
(
job
.
timeout_ident
);
delete
job
.
timeout_ident
;
}
function
restartJobTimeoutIfRunning
(
job
)
{
clearTimeout
(
job
.
timeout_ident
);
if
(
job
.
state
===
'
running
'
&&
job
.
timeout
>
0
)
{
job
.
timeout_ident
=
setTimeout
(
timeoutReject
(
job
),
job
.
timeout
);
job
.
modified
=
new
Date
();
}
else
{
delete
job
.
timeout_ident
;
}
}
// listeners
shared
.
on
(
'
job:new
'
,
initJob
);
[
"
jobDone
"
,
"
jobFail
"
,
"
jobRetry
"
].
forEach
(
function
(
event
)
{
shared
.
on
(
"
job:stopped
"
,
clearJobTimeout
);
shared
.
on
(
event
,
function
(
param
)
{
shared
.
on
(
"
job:end
"
,
clearJobTimeout
);
clearTimeout
(
param
.
timeout_ident
);
delete
param
.
timeout_ident
;
});
});
[
"
jobRun
"
,
"
jobNotify
"
,
"
jobEnd
"
].
forEach
(
function
(
event
)
{
shared
.
on
(
"
job:started
"
,
restartJobTimeoutIfRunning
);
shared
.
on
(
event
,
function
(
param
)
{
shared
.
on
(
"
job:notified
"
,
restartJobTimeoutIfRunning
);
clearTimeout
(
param
.
timeout_ident
);
if
(
param
.
state
===
'
running
'
&&
param
.
timeout
>
0
)
{
param
.
timeout_ident
=
setTimeout
(
timeoutReject
(
param
),
param
.
timeout
);
param
.
modified
=
new
Date
();
}
else
{
delete
param
.
timeout_ident
;
}
});
});
}
}
test/jio/tests.js
View file @
298da338
...
@@ -668,8 +668,8 @@
...
@@ -668,8 +668,8 @@
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Job Manage
"
},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
1 Job Manage
"
},
"
method
"
:
"
get
"
,
"
method
"
:
"
get
"
,
//"created": new Date(),
//"created": new Date(),
"
tried
"
:
1
,
"
tried
"
:
0
,
// deferred writing 1
"
state
"
:
"
r
unning
"
,
"
state
"
:
"
r
eady
"
,
// deferred writing "running"
//"modified": new Date(),
//"modified": new Date(),
"
max_retry
"
:
2
,
"
max_retry
"
:
2
,
"
timeout
"
:
1200
,
"
timeout
"
:
1200
,
...
@@ -683,7 +683,7 @@
...
@@ -683,7 +683,7 @@
setTimeout
(
function
()
{
setTimeout
(
function
()
{
commands
[
"
1 Job Manage/get
"
].
success
({
"
data
"
:
{
"
b
"
:
"
c
"
}});
commands
[
"
1 Job Manage/get
"
].
success
({
"
data
"
:
{
"
b
"
:
"
c
"
}});
},
50
);
// wait 5
0 ms
},
100
);
// wait 10
0 ms
setTimeout
(
function
()
{
setTimeout
(
function
()
{
deepEqual
(
workspace
,
{},
'
Job ended, empty workspace
'
);
deepEqual
(
workspace
,
{},
'
Job ended, empty workspace
'
);
...
@@ -703,7 +703,7 @@
...
@@ -703,7 +703,7 @@
o
.
job1
.
kwargs
.
_id
=
'
b
'
;
o
.
job1
.
kwargs
.
_id
=
'
b
'
;
// o.job1.created = new Date();
// o.job1.created = new Date();
// o.job1.modified = new Date();
// o.job1.modified = new Date();
},
100
);
// wait 5
0 ms
},
200
);
// wait 10
0 ms
setTimeout
(
function
()
{
setTimeout
(
function
()
{
commands
[
"
1 Job Manage/get
"
].
storage
({
commands
[
"
1 Job Manage/get
"
].
storage
({
"
type
"
:
"
fake
"
,
"
type
"
:
"
fake
"
,
...
@@ -720,19 +720,23 @@
...
@@ -720,19 +720,23 @@
},
"
Second job respond
"
);
},
"
Second job respond
"
);
});
});
o
.
job1
.
tried
=
1
;
o
.
job1
.
state
=
'
running
'
;
o
.
job2
=
{
o
.
job2
=
{
"
kwargs
"
:
{
"
_id
"
:
"
c
"
},
"
kwargs
"
:
{
"
_id
"
:
"
c
"
},
"
options
"
:
{},
"
options
"
:
{},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 Job Manage
"
},
"
storage_spec
"
:
{
"
type
"
:
"
fake
"
,
"
id
"
:
"
2 Job Manage
"
},
"
method
"
:
"
get
"
,
"
method
"
:
"
get
"
,
//"created": new Date(),
//"created": new Date(),
"
tried
"
:
1
,
"
tried
"
:
0
,
// deferred writing 1
"
state
"
:
"
r
unning
"
,
"
state
"
:
"
r
eady
"
,
// deferred writing "running"
//"modified": new Date(),
//"modified": new Date(),
"
max_retry
"
:
2
,
"
max_retry
"
:
2
,
"
timeout
"
:
10000
,
"
timeout
"
:
10000
,
"
id
"
:
2
"
id
"
:
2
};
};
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
tmp
=
JSON
.
parse
(
tmp
);
tmp
=
JSON
.
parse
(
tmp
);
delete
tmp
[
0
].
created
;
delete
tmp
[
0
].
created
;
...
@@ -743,20 +747,24 @@
...
@@ -743,20 +747,24 @@
o
.
job1
,
o
.
job1
,
o
.
job2
o
.
job2
],
'
Job calls another job, workspace have two jobs
'
);
],
'
Job calls another job, workspace have two jobs
'
);
},
150
);
// wait 5
0 ms
},
300
);
// wait 10
0 ms
setTimeout
(
function
()
{
setTimeout
(
function
()
{
commands
[
'
1 Job Manage/get
'
].
end
();
commands
[
'
1 Job Manage/get
'
].
end
();
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
tmp
=
workspace
[
"
jio/jobs/{
\"
id
\"
:
\"
1 Job Manage
\"
,
\"
type
\"
:
\"
fake
\"
}
"
];
tmp
=
JSON
.
parse
(
tmp
);
tmp
=
JSON
.
parse
(
tmp
);
delete
tmp
[
0
].
created
;
delete
tmp
[
0
].
created
;
delete
tmp
[
0
].
modified
;
delete
tmp
[
0
].
modified
;
o
.
job2
.
tried
=
1
;
o
.
job2
.
state
=
'
running
'
;
deepEqual
(
tmp
,
[
o
.
job2
],
'
First Job ended, second still there
'
);
deepEqual
(
tmp
,
[
o
.
job2
],
'
First Job ended, second still there
'
);
commands
[
'
1 Job Manage/get
'
].
success
({
"
data
"
:
{
"
c
"
:
"
d
"
}});
commands
[
'
1 Job Manage/get
'
].
success
({
"
data
"
:
{
"
c
"
:
"
d
"
}});
commands
[
'
2 Job Manage/get
'
].
success
({
"
data
"
:
{
"
d
"
:
"
e
"
}});
commands
[
'
2 Job Manage/get
'
].
success
({
"
data
"
:
{
"
d
"
:
"
e
"
}});
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
},
200
);
// wait 5
0 ms
},
400
);
// wait 10
0 ms
});
});
test
(
'
job state running, job recovery
'
,
2
,
function
()
{
test
(
'
job state running, job recovery
'
,
2
,
function
()
{
...
@@ -831,8 +839,11 @@
...
@@ -831,8 +839,11 @@
setTimeout
(
function
()
{
setTimeout
(
function
()
{
// copy workspace when job is waiting
// copy workspace when job is waiting
commands
[
'
Job Recovw/post
'
].
retry
();
commands
[
'
Job Recovw/post
'
].
retry
();
workspace
=
jIO
.
util
.
deepClone
(
workspace
);
},
50
);
},
50
);
setTimeout
(
function
()
{
workspace
=
jIO
.
util
.
deepClone
(
workspace
);
},
100
);
setTimeout
(
function
()
{
setTimeout
(
function
()
{
commands
[
'
Job Recovw/post
'
].
success
({
"
id
"
:
"
a
"
});
commands
[
'
Job Recovw/post
'
].
success
({
"
id
"
:
"
a
"
});
},
2100
);
},
2100
);
...
@@ -850,7 +861,7 @@
...
@@ -850,7 +861,7 @@
if
(
commands
[
'
Job Recovw/post
'
])
{
if
(
commands
[
'
Job Recovw/post
'
])
{
ok
(
false
,
"
Command called, job recovered to earlier
"
);
ok
(
false
,
"
Command called, job recovered to earlier
"
);
}
}
},
19
999
);
},
19
889
);
// need to wait around 19900 ms
setTimeout
(
function
()
{
setTimeout
(
function
()
{
if
(
!
commands
[
'
Job Recovw/post
'
])
{
if
(
!
commands
[
'
Job Recovw/post
'
])
{
...
@@ -865,7 +876,7 @@
...
@@ -865,7 +876,7 @@
start
();
start
();
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
deepEqual
(
workspace
,
{},
'
No more job in the queue
'
);
},
20100
);
},
20100
);
},
51
);
},
150
);
//////////////////////////////
//////////////////////////////
// XXX Waiting for jobs job recovery
// XXX Waiting for jobs job recovery
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment