Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
jio
Commits
ee06ecb8
Commit
ee06ecb8
authored
Jan 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass job.js
parent
1527f4a9
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
201 additions
and
177 deletions
+201
-177
src/jio/jobs/job.js
src/jio/jobs/job.js
+201
-177
No files found.
src/jio/jobs/job.js
View file @
ee06ecb8
var
job
=
function
(
spec
)
{
var
that
=
{};
/*jslint indent: 2, maxlen: 80, sloppy: true */
/*global jobIdHandler: true, initialStatus: true, invalidJobException: true,
waitStatus: true, failStatus: true, tooMuchTriesJobException: true,
jobManager: true, jobNotReadyException: true, onGoingStatus: true */
var
job
=
function
(
spec
)
{
var
that
=
{},
priv
=
{};
spec
=
spec
||
{};
// Attributes //
var
priv
=
{};
priv
.
id
=
jobIdHandler
.
nextId
();
priv
.
command
=
spec
.
command
;
priv
.
storage
=
spec
.
storage
;
...
...
@@ -10,11 +15,17 @@ var job = function(spec) {
priv
.
date
=
new
Date
();
// Initialize //
if
(
!
priv
.
storage
){
throw
invalidJobException
({
job
:
that
,
message
:
'
No storage set
'
});
if
(
!
priv
.
storage
)
{
throw
invalidJobException
({
job
:
that
,
message
:
'
No storage set
'
});
}
if
(
!
priv
.
command
){
throw
invalidJobException
({
job
:
that
,
message
:
'
No command set
'
});
if
(
!
priv
.
command
)
{
throw
invalidJobException
({
job
:
that
,
message
:
'
No command set
'
});
}
// Methods //
/**
...
...
@@ -22,23 +33,23 @@ var job = function(spec) {
* @method getCommand
* @return {object} The job command.
*/
that
.
getCommand
=
function
()
{
that
.
getCommand
=
function
()
{
return
priv
.
command
;
};
that
.
getStatus
=
function
()
{
that
.
getStatus
=
function
()
{
return
priv
.
status
;
};
that
.
getId
=
function
()
{
that
.
getId
=
function
()
{
return
priv
.
id
;
};
that
.
getStorage
=
function
()
{
that
.
getStorage
=
function
()
{
return
priv
.
storage
;
};
that
.
getDate
=
function
()
{
that
.
getDate
=
function
()
{
return
priv
.
date
;
};
...
...
@@ -47,12 +58,11 @@ var job = function(spec) {
* @method isReady
* @return {boolean} true if ready, else false.
*/
that
.
isReady
=
function
()
{
that
.
isReady
=
function
()
{
if
(
priv
.
command
.
getTried
()
===
0
)
{
return
priv
.
status
.
canStart
();
}
else
{
return
priv
.
status
.
canRestart
();
}
return
priv
.
status
.
canRestart
();
};
/**
...
...
@@ -60,12 +70,14 @@ var job = function(spec) {
* @method serialized
* @return {object} The serialized job.
*/
that
.
serialized
=
function
()
{
return
{
id
:
priv
.
id
,
date
:
priv
.
date
.
getTime
(),
status
:
priv
.
status
.
serialized
(),
command
:
priv
.
command
.
serialized
(),
storage
:
priv
.
storage
.
serialized
()};
that
.
serialized
=
function
()
{
return
{
id
:
priv
.
id
,
date
:
priv
.
date
.
getTime
(),
status
:
priv
.
status
.
serialized
(),
command
:
priv
.
command
.
serialized
(),
storage
:
priv
.
storage
.
serialized
()
};
};
/**
...
...
@@ -73,7 +85,7 @@ var job = function(spec) {
* @method waitForJob
* @param {object} job The job to wait for.
*/
that
.
waitForJob
=
function
(
job
)
{
that
.
waitForJob
=
function
(
job
)
{
if
(
priv
.
status
.
getLabel
()
!==
'
wait
'
)
{
priv
.
status
=
waitStatus
({});
}
...
...
@@ -85,7 +97,7 @@ var job = function(spec) {
* @method dontWaitForJob
* @param {object} job The other job.
*/
that
.
dontWaitFor
=
function
(
job
)
{
that
.
dontWaitFor
=
function
(
job
)
{
if
(
priv
.
status
.
getLabel
()
===
'
wait
'
)
{
priv
.
status
.
dontWaitForJob
(
job
);
}
...
...
@@ -96,7 +108,7 @@ var job = function(spec) {
* @method waitForTime
* @param {number} ms Time to wait in millisecond.
*/
that
.
waitForTime
=
function
(
ms
)
{
that
.
waitForTime
=
function
(
ms
)
{
if
(
priv
.
status
.
getLabel
()
!==
'
wait
'
)
{
priv
.
status
=
waitStatus
({});
}
...
...
@@ -107,28 +119,34 @@ var job = function(spec) {
* Tells the job to do not wait for a while anymore.
* @method stopWaitForTime
*/
that
.
stopWaitForTime
=
function
()
{
that
.
stopWaitForTime
=
function
()
{
if
(
priv
.
status
.
getLabel
()
===
'
wait
'
)
{
priv
.
status
.
stopWaitForTime
();
}
};
that
.
eliminated
=
function
()
{
priv
.
command
.
error
({
status
:
10
,
statusText
:
'
Stopped
'
,
error
:
'
stopped
'
,
message
:
'
This job has been stopped by another one.
'
,
reason
:
'
this job has been stopped by another one
'
});
priv
.
command
.
error
({
status
:
10
,
statusText
:
'
Stopped
'
,
error
:
'
stopped
'
,
message
:
'
This job has been stopped by another one.
'
,
reason
:
'
this job has been stopped by another one
'
});
};
that
.
notAccepted
=
function
()
{
priv
.
command
.
onEndDo
(
function
()
{
priv
.
command
.
onEndDo
(
function
()
{
priv
.
status
=
failStatus
();
jobManager
.
terminateJob
(
that
);
jobManager
.
terminateJob
(
that
);
});
priv
.
command
.
error
({
status
:
11
,
statusText
:
'
Not Accepted
'
,
error
:
'
not_accepted
'
,
message
:
'
This job is already running.
'
,
reason
:
'
this job is already running
'
});
priv
.
command
.
error
({
status
:
11
,
statusText
:
'
Not Accepted
'
,
error
:
'
not_accepted
'
,
message
:
'
This job is already running.
'
,
reason
:
'
this job is already running
'
});
};
/**
...
...
@@ -136,11 +154,14 @@ var job = function(spec) {
* @method update
* @param {object} job The other job.
*/
that
.
update
=
function
(
job
)
{
priv
.
command
.
error
({
status
:
12
,
statusText
:
'
Replaced
'
,
error
:
'
replaced
'
,
message
:
'
Job has been replaced by another one.
'
,
reason
:
'
job has been replaced by another one
'
});
that
.
update
=
function
(
job
)
{
priv
.
command
.
error
({
status
:
12
,
statusText
:
'
Replaced
'
,
error
:
'
replaced
'
,
message
:
'
Job has been replaced by another one.
'
,
reason
:
'
job has been replaced by another one
'
});
priv
.
date
=
new
Date
(
job
.
getDate
().
getTime
());
priv
.
command
=
job
.
getCommand
();
priv
.
status
=
job
.
getStatus
();
...
...
@@ -150,30 +171,33 @@ var job = function(spec) {
* Executes this job.
* @method execute
*/
that
.
execute
=
function
()
{
that
.
execute
=
function
()
{
if
(
!
that
.
getCommand
().
canBeRetried
())
{
throw
tooMuchTriesJobException
(
{
job
:
that
,
message
:
'
The job was invoked too much time.
'
});
throw
tooMuchTriesJobException
({
job
:
that
,
message
:
'
The job was invoked too much time.
'
});
}
if
(
!
that
.
isReady
())
{
throw
jobNotReadyException
(
{
job
:
that
,
message
:
'
Can not execute this job.
'
});
throw
jobNotReadyException
({
job
:
that
,
message
:
'
Can not execute this job.
'
});
}
priv
.
status
=
onGoingStatus
();
priv
.
command
.
onRetryDo
(
function
()
{
priv
.
command
.
onRetryDo
(
function
()
{
var
ms
=
priv
.
command
.
getTried
();
ms
=
ms
*
ms
*
200
;
if
(
ms
>
10000
)
{
ms
=
ms
*
ms
*
200
;
if
(
ms
>
10000
)
{
ms
=
10000
;
}
that
.
waitForTime
(
ms
);
});
priv
.
command
.
onEndDo
(
function
(
status
)
{
priv
.
command
.
onEndDo
(
function
(
status
)
{
priv
.
status
=
status
;
jobManager
.
terminateJob
(
that
);
jobManager
.
terminateJob
(
that
);
});
priv
.
command
.
execute
(
priv
.
storage
);
priv
.
command
.
execute
(
priv
.
storage
);
};
return
that
;
};
\ No newline at end of file
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