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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
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
)
{
/*jslint indent: 2, maxlen: 80, sloppy: true */
var
that
=
{};
/*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
||
{};
spec
=
spec
||
{};
// Attributes //
var
priv
=
{};
priv
.
id
=
jobIdHandler
.
nextId
();
priv
.
id
=
jobIdHandler
.
nextId
();
priv
.
command
=
spec
.
command
;
priv
.
command
=
spec
.
command
;
priv
.
storage
=
spec
.
storage
;
priv
.
storage
=
spec
.
storage
;
...
@@ -10,11 +15,17 @@ var job = function(spec) {
...
@@ -10,11 +15,17 @@ var job = function(spec) {
priv
.
date
=
new
Date
();
priv
.
date
=
new
Date
();
// Initialize //
// Initialize //
if
(
!
priv
.
storage
){
if
(
!
priv
.
storage
)
{
throw
invalidJobException
({
job
:
that
,
message
:
'
No storage set
'
});
throw
invalidJobException
({
job
:
that
,
message
:
'
No storage set
'
});
}
}
if
(
!
priv
.
command
){
if
(
!
priv
.
command
)
{
throw
invalidJobException
({
job
:
that
,
message
:
'
No command set
'
});
throw
invalidJobException
({
job
:
that
,
message
:
'
No command set
'
});
}
}
// Methods //
// Methods //
/**
/**
...
@@ -22,23 +33,23 @@ var job = function(spec) {
...
@@ -22,23 +33,23 @@ var job = function(spec) {
* @method getCommand
* @method getCommand
* @return {object} The job command.
* @return {object} The job command.
*/
*/
that
.
getCommand
=
function
()
{
that
.
getCommand
=
function
()
{
return
priv
.
command
;
return
priv
.
command
;
};
};
that
.
getStatus
=
function
()
{
that
.
getStatus
=
function
()
{
return
priv
.
status
;
return
priv
.
status
;
};
};
that
.
getId
=
function
()
{
that
.
getId
=
function
()
{
return
priv
.
id
;
return
priv
.
id
;
};
};
that
.
getStorage
=
function
()
{
that
.
getStorage
=
function
()
{
return
priv
.
storage
;
return
priv
.
storage
;
};
};
that
.
getDate
=
function
()
{
that
.
getDate
=
function
()
{
return
priv
.
date
;
return
priv
.
date
;
};
};
...
@@ -47,12 +58,11 @@ var job = function(spec) {
...
@@ -47,12 +58,11 @@ var job = function(spec) {
* @method isReady
* @method isReady
* @return {boolean} true if ready, else false.
* @return {boolean} true if ready, else false.
*/
*/
that
.
isReady
=
function
()
{
that
.
isReady
=
function
()
{
if
(
priv
.
command
.
getTried
()
===
0
)
{
if
(
priv
.
command
.
getTried
()
===
0
)
{
return
priv
.
status
.
canStart
();
return
priv
.
status
.
canStart
();
}
else
{
return
priv
.
status
.
canRestart
();
}
}
return
priv
.
status
.
canRestart
();
};
};
/**
/**
...
@@ -60,12 +70,14 @@ var job = function(spec) {
...
@@ -60,12 +70,14 @@ var job = function(spec) {
* @method serialized
* @method serialized
* @return {object} The serialized job.
* @return {object} The serialized job.
*/
*/
that
.
serialized
=
function
()
{
that
.
serialized
=
function
()
{
return
{
id
:
priv
.
id
,
return
{
date
:
priv
.
date
.
getTime
(),
id
:
priv
.
id
,
status
:
priv
.
status
.
serialized
(),
date
:
priv
.
date
.
getTime
(),
command
:
priv
.
command
.
serialized
(),
status
:
priv
.
status
.
serialized
(),
storage
:
priv
.
storage
.
serialized
()};
command
:
priv
.
command
.
serialized
(),
storage
:
priv
.
storage
.
serialized
()
};
};
};
/**
/**
...
@@ -73,7 +85,7 @@ var job = function(spec) {
...
@@ -73,7 +85,7 @@ var job = function(spec) {
* @method waitForJob
* @method waitForJob
* @param {object} job The job to wait for.
* @param {object} job The job to wait for.
*/
*/
that
.
waitForJob
=
function
(
job
)
{
that
.
waitForJob
=
function
(
job
)
{
if
(
priv
.
status
.
getLabel
()
!==
'
wait
'
)
{
if
(
priv
.
status
.
getLabel
()
!==
'
wait
'
)
{
priv
.
status
=
waitStatus
({});
priv
.
status
=
waitStatus
({});
}
}
...
@@ -85,7 +97,7 @@ var job = function(spec) {
...
@@ -85,7 +97,7 @@ var job = function(spec) {
* @method dontWaitForJob
* @method dontWaitForJob
* @param {object} job The other job.
* @param {object} job The other job.
*/
*/
that
.
dontWaitFor
=
function
(
job
)
{
that
.
dontWaitFor
=
function
(
job
)
{
if
(
priv
.
status
.
getLabel
()
===
'
wait
'
)
{
if
(
priv
.
status
.
getLabel
()
===
'
wait
'
)
{
priv
.
status
.
dontWaitForJob
(
job
);
priv
.
status
.
dontWaitForJob
(
job
);
}
}
...
@@ -96,7 +108,7 @@ var job = function(spec) {
...
@@ -96,7 +108,7 @@ var job = function(spec) {
* @method waitForTime
* @method waitForTime
* @param {number} ms Time to wait in millisecond.
* @param {number} ms Time to wait in millisecond.
*/
*/
that
.
waitForTime
=
function
(
ms
)
{
that
.
waitForTime
=
function
(
ms
)
{
if
(
priv
.
status
.
getLabel
()
!==
'
wait
'
)
{
if
(
priv
.
status
.
getLabel
()
!==
'
wait
'
)
{
priv
.
status
=
waitStatus
({});
priv
.
status
=
waitStatus
({});
}
}
...
@@ -107,28 +119,34 @@ var job = function(spec) {
...
@@ -107,28 +119,34 @@ var job = function(spec) {
* Tells the job to do not wait for a while anymore.
* Tells the job to do not wait for a while anymore.
* @method stopWaitForTime
* @method stopWaitForTime
*/
*/
that
.
stopWaitForTime
=
function
()
{
that
.
stopWaitForTime
=
function
()
{
if
(
priv
.
status
.
getLabel
()
===
'
wait
'
)
{
if
(
priv
.
status
.
getLabel
()
===
'
wait
'
)
{
priv
.
status
.
stopWaitForTime
();
priv
.
status
.
stopWaitForTime
();
}
}
};
};
that
.
eliminated
=
function
()
{
that
.
eliminated
=
function
()
{
priv
.
command
.
error
({
priv
.
command
.
error
({
status
:
10
,
statusText
:
'
Stopped
'
,
error
:
'
stopped
'
,
status
:
10
,
message
:
'
This job has been stopped by another one.
'
,
statusText
:
'
Stopped
'
,
reason
:
'
this job has been stopped by another one
'
});
error
:
'
stopped
'
,
message
:
'
This job has been stopped by another one.
'
,
reason
:
'
this job has been stopped by another one
'
});
};
};
that
.
notAccepted
=
function
()
{
that
.
notAccepted
=
function
()
{
priv
.
command
.
onEndDo
(
function
()
{
priv
.
command
.
onEndDo
(
function
()
{
priv
.
status
=
failStatus
();
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) {
...
@@ -136,11 +154,14 @@ var job = function(spec) {
* @method update
* @method update
* @param {object} job The other job.
* @param {object} job The other job.
*/
*/
that
.
update
=
function
(
job
)
{
that
.
update
=
function
(
job
)
{
priv
.
command
.
error
({
priv
.
command
.
error
({
status
:
12
,
statusText
:
'
Replaced
'
,
error
:
'
replaced
'
,
status
:
12
,
message
:
'
Job has been replaced by another one.
'
,
statusText
:
'
Replaced
'
,
reason
:
'
job has been replaced by another one
'
});
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
.
date
=
new
Date
(
job
.
getDate
().
getTime
());
priv
.
command
=
job
.
getCommand
();
priv
.
command
=
job
.
getCommand
();
priv
.
status
=
job
.
getStatus
();
priv
.
status
=
job
.
getStatus
();
...
@@ -150,30 +171,33 @@ var job = function(spec) {
...
@@ -150,30 +171,33 @@ var job = function(spec) {
* Executes this job.
* Executes this job.
* @method execute
* @method execute
*/
*/
that
.
execute
=
function
()
{
that
.
execute
=
function
()
{
if
(
!
that
.
getCommand
().
canBeRetried
())
{
if
(
!
that
.
getCommand
().
canBeRetried
())
{
throw
tooMuchTriesJobException
(
throw
tooMuchTriesJobException
({
{
job
:
that
,
message
:
'
The job was invoked too much time.
'
});
job
:
that
,
message
:
'
The job was invoked too much time.
'
});
}
}
if
(
!
that
.
isReady
())
{
if
(
!
that
.
isReady
())
{
throw
jobNotReadyException
(
throw
jobNotReadyException
({
{
job
:
that
,
message
:
'
Can not execute this job.
'
});
job
:
that
,
message
:
'
Can not execute this job.
'
});
}
}
priv
.
status
=
onGoingStatus
();
priv
.
status
=
onGoingStatus
();
priv
.
command
.
onRetryDo
(
function
()
{
priv
.
command
.
onRetryDo
(
function
()
{
var
ms
=
priv
.
command
.
getTried
();
var
ms
=
priv
.
command
.
getTried
();
ms
=
ms
*
ms
*
200
;
ms
=
ms
*
ms
*
200
;
if
(
ms
>
10000
)
{
if
(
ms
>
10000
)
{
ms
=
10000
;
ms
=
10000
;
}
}
that
.
waitForTime
(
ms
);
that
.
waitForTime
(
ms
);
});
});
priv
.
command
.
onEndDo
(
function
(
status
)
{
priv
.
command
.
onEndDo
(
function
(
status
)
{
priv
.
status
=
status
;
priv
.
status
=
status
;
jobManager
.
terminateJob
(
that
);
jobManager
.
terminateJob
(
that
);
});
});
priv
.
command
.
execute
(
priv
.
storage
);
priv
.
command
.
execute
(
priv
.
storage
);
};
};
return
that
;
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