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
Tomáš Peterka
jio
Commits
4a533092
Commit
4a533092
authored
Aug 26, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change JobWorkspace to JobQueue
parent
2c44a65a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
68 additions
and
120 deletions
+68
-120
src/jio/core/JobQueue.js
src/jio/core/JobQueue.js
+64
-4
src/jio/core/JobWorkspace.js
src/jio/core/JobWorkspace.js
+0
-111
src/jio/features/jobQueue.js
src/jio/features/jobQueue.js
+3
-4
src/jio/features/jobRecovery.js
src/jio/features/jobRecovery.js
+1
-1
No files found.
src/jio/core/JobQueue.js
View file @
4a533092
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global deepClone */
/*global deepClone
, dictFilter, uniqueJSONStringify
*/
/**
/**
* Tool to manipulate a list of object containing at least one property: 'id'.
* Tool to manipulate a list of object containing at least one property: 'id'.
...
@@ -7,12 +7,72 @@
...
@@ -7,12 +7,72 @@
*
*
* @class JobQueue
* @class JobQueue
* @constructor
* @constructor
* @param {Array} An array of object
* @param {Workspace} workspace The workspace where to store
* @param {String} namespace The namespace to use in the workspace
* @param {Array} job_keys An array of job keys to store
* @param {Array} [array] An array of object
*/
*/
function
JobQueue
(
array
)
{
function
JobQueue
(
workspace
,
namespace
,
job_keys
,
array
)
{
this
.
_array
=
array
;
this
.
_workspace
=
workspace
;
this
.
_namespace
=
namespace
;
this
.
_job_keys
=
job_keys
;
if
(
Array
.
isArray
(
array
))
{
this
.
_array
=
array
;
}
else
{
this
.
_array
=
[];
}
}
}
/**
* Store the job queue into the workspace.
*
* @method save
*/
JobQueue
.
prototype
.
save
=
function
()
{
var
i
,
job_queue
=
deepClone
(
this
.
_array
);
for
(
i
=
0
;
i
<
job_queue
.
length
;
i
+=
1
)
{
dictFilter
(
job_queue
[
i
],
this
.
_job_keys
);
}
if
(
this
.
_array
.
length
===
0
)
{
this
.
_workspace
.
removeItem
(
this
.
_namespace
);
}
else
{
this
.
_workspace
.
setItem
(
this
.
_namespace
,
uniqueJSONStringify
(
job_queue
)
);
}
return
this
;
};
/**
* Loads the job queue from the workspace.
*
* @method load
*/
JobQueue
.
prototype
.
load
=
function
()
{
var
job_list
;
try
{
job_list
=
JSON
.
parse
(
this
.
_workspace
.
getItem
(
this
.
_namespace
));
}
catch
(
ignore
)
{}
if
(
!
Array
.
isArray
(
job_list
))
{
job_list
=
[];
}
this
.
clear
();
new
JobQueue
(
job_list
).
repair
();
this
.
update
(
job_list
);
return
this
;
};
/**
* Returns the array version of the job queue
*
* @method asArray
* @return {Array} The job queue as array
*/
JobQueue
.
prototype
.
asArray
=
function
()
{
return
this
.
_array
;
};
/**
/**
* Removes elements which are not objects containing at least 'id' property.
* Removes elements which are not objects containing at least 'id' property.
*
*
...
...
src/jio/core/JobWorkspace.js
deleted
100644 → 0
View file @
2c44a65a
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global JobQueue, uniqueJSONStringify, deepClone, dictFilter */
/**
* Manipulates a job queue and is also able to store it in a specific place.
*
* @class JobWorkspace
* @constructor
* @param {Workspace} workspace The workspace where to store
* @param {JobQueue} job_queue The job queue to use
* @param {String} namespace The namespace to use in the workspace
* @param {Array} job_keys An array of job keys to store
*/
function
JobWorkspace
(
workspace
,
job_queue
,
namespace
,
job_keys
)
{
this
.
_workspace
=
workspace
;
this
.
_job_queue
=
job_queue
;
this
.
_namespace
=
namespace
;
this
.
_job_keys
=
job_keys
;
}
/**
* Store the job queue into the workspace.
*
* @method save
*/
JobWorkspace
.
prototype
.
save
=
function
()
{
var
i
,
job_queue
=
deepClone
(
this
.
_job_queue
.
_array
);
for
(
i
=
0
;
i
<
job_queue
.
length
;
i
+=
1
)
{
dictFilter
(
job_queue
[
i
],
this
.
_job_keys
);
}
if
(
this
.
_job_queue
.
_array
.
length
===
0
)
{
this
.
_workspace
.
removeItem
(
this
.
_namespace
);
}
else
{
this
.
_workspace
.
setItem
(
this
.
_namespace
,
uniqueJSONStringify
(
job_queue
)
);
}
return
this
;
};
/**
* Loads the job queue from the workspace.
*
* @method load
*/
JobWorkspace
.
prototype
.
load
=
function
()
{
var
job_list
;
try
{
job_list
=
JSON
.
parse
(
this
.
_workspace
.
getItem
(
this
.
_namespace
));
}
catch
(
ignore
)
{}
if
(
!
Array
.
isArray
(
job_list
))
{
job_list
=
[];
}
this
.
_job_queue
.
clear
();
new
JobQueue
(
job_list
).
repair
();
this
.
_job_queue
.
update
(
job_list
);
return
this
;
};
/**
* Returns the array version of the job queue
*
* @method asArray
* @return {Array} The job queue as array
*/
JobWorkspace
.
prototype
.
asArray
=
function
()
{
return
this
.
_job_queue
.
_array
;
};
/**
* Post a job in the job queue
*
* @method post
* @param {Object} job The job object
* @return {Number} The generated id
*/
JobWorkspace
.
prototype
.
post
=
function
(
job
)
{
return
this
.
_job_queue
.
post
(
job
);
};
/**
* Put a job to the job queue
*
* @method put
* @param {Object} job The job object with an id
*/
JobWorkspace
.
prototype
.
put
=
function
(
job
)
{
return
this
.
_job_queue
.
put
(
job
);
};
/**
* Get a job from an id. Returns undefined if not found
*
* @method get
* @param {Number} id The job id
* @return {Object} The job or undefined
*/
JobWorkspace
.
prototype
.
get
=
function
(
id
)
{
return
this
.
_job_queue
.
get
(
id
);
};
/**
* Removes a job from an id
*
* @method remove
* @param {Number} id The job id
*/
JobWorkspace
.
prototype
.
remove
=
function
(
id
)
{
return
this
.
_job_queue
.
remove
(
id
);
};
src/jio/features/jobQueue.js
View file @
4a533092
/*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,
JobWorkspace,
constants */
constants */
function
enableJobQueue
(
jio
,
shared
,
options
)
{
function
enableJobQueue
(
jio
,
shared
,
options
)
{
...
@@ -14,7 +14,7 @@ function enableJobQueue(jio, shared, options) {
...
@@ -14,7 +14,7 @@ function enableJobQueue(jio, shared, options) {
// creates
// creates
// - shared.storage_spec_str String
// - shared.storage_spec_str String
// - shared.workspace Workspace
// - shared.workspace Workspace
// - shared.job_queue Job
Workspac
e
// - shared.job_queue Job
Queu
e
// uses 'job', 'jobRun', 'jobStop', 'jobEnd' events
// uses 'job', 'jobRun', 'jobStop', 'jobEnd' events
// emits 'jobEnd' events
// emits 'jobEnd' events
...
@@ -33,9 +33,8 @@ function enableJobQueue(jio, shared, options) {
...
@@ -33,9 +33,8 @@ function enableJobQueue(jio, shared, options) {
shared
.
storage_spec_str
=
uniqueJSONStringify
(
shared
.
storage_spec
);
shared
.
storage_spec_str
=
uniqueJSONStringify
(
shared
.
storage_spec
);
}
}
shared
.
job_queue
=
new
Job
Workspac
e
(
shared
.
job_queue
=
new
Job
Queu
e
(
shared
.
workspace
,
shared
.
workspace
,
new
JobQueue
([]),
'
jio/jobs/
'
+
shared
.
storage_spec_str
,
'
jio/jobs/
'
+
shared
.
storage_spec_str
,
shared
.
job_keys
shared
.
job_keys
);
);
...
...
src/jio/features/jobRecovery.js
View file @
4a533092
...
@@ -7,7 +7,7 @@ function enableJobRecovery(jio, shared, options) {
...
@@ -7,7 +7,7 @@ function enableJobRecovery(jio, shared, options) {
// - JobQueue enabled and before this
// - JobQueue enabled and before this
// uses
// uses
// - shared.job_queue Job
Workspac
e
// - shared.job_queue Job
Queu
e
function
numberOrDefault
(
number
,
default_value
)
{
function
numberOrDefault
(
number
,
default_value
)
{
return
(
typeof
number
===
'
number
'
&&
return
(
typeof
number
===
'
number
'
&&
...
...
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