Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
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
Alexandra Rogova
jio_mebibou
Commits
5260fbb8
Commit
5260fbb8
authored
Aug 23, 2013
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jobChecker enabled (does nothing yet)
parent
1e9dab69
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
267 additions
and
2 deletions
+267
-2
src/jio/core/JIO.js
src/jio/core/JIO.js
+1
-1
src/jio/core/globals.js
src/jio/core/globals.js
+131
-1
src/jio/features/jobChecker.js
src/jio/features/jobChecker.js
+135
-0
No files found.
src/jio/core/JIO.js
View file @
5260fbb8
...
@@ -20,7 +20,7 @@ function JIO(storage_spec, options) {
...
@@ -20,7 +20,7 @@ function JIO(storage_spec, options) {
enableRestParamChecker
(
that
,
shared
,
options
);
enableRestParamChecker
(
that
,
shared
,
options
);
enableJobMaker
(
that
,
shared
,
options
);
enableJobMaker
(
that
,
shared
,
options
);
enableJobRetry
(
that
,
shared
,
options
);
enableJobRetry
(
that
,
shared
,
options
);
//
enableJobChecker(that, shared, options);
enableJobChecker
(
that
,
shared
,
options
);
enableJobQueue
(
that
,
shared
,
options
);
enableJobQueue
(
that
,
shared
,
options
);
enableJobRecovery
(
that
,
shared
,
options
);
enableJobRecovery
(
that
,
shared
,
options
);
enableJobTimeout
(
that
,
shared
,
options
);
enableJobTimeout
(
that
,
shared
,
options
);
...
...
src/jio/core/globals.js
View file @
5260fbb8
/*jslint indent: 2, maxlen: 80, sloppy: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global uniqueJSONStringify */
var
defaults
=
{},
constants
=
{};
var
defaults
=
{},
constants
=
{};
...
@@ -330,6 +331,135 @@ constants.http_action = {
...
@@ -330,6 +331,135 @@ constants.http_action = {
constants
.
content_type_re
=
constants
.
content_type_re
=
/^
([
a-z
]
+
\/[
a-zA-Z0-9
\+\-\.]
+
)(?:\s
*;
\s
*charset
\s
*=
\s
*
([
a-zA-Z0-9
\-]
+
))?
$/
;
/^
([
a-z
]
+
\/[
a-zA-Z0-9
\+\-\.]
+
)(?:\s
*;
\s
*charset
\s
*=
\s
*
([
a-zA-Z0-9
\-]
+
))?
$/
;
/**
* Function that does nothing
*/
constants
.
emptyFunction
=
function
()
{
constants
.
emptyFunction
=
function
()
{
return
;
return
;
};
};
defaults
.
job_rule_actions
=
{};
/**
* Adds some job rule actions
*/
(
function
()
{
/**
* Compare two jobs and test if they use the same storage description
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
sameStorageDescription
(
a
,
b
)
{
return
uniqueJSONStringify
(
a
.
storage_spec
)
===
uniqueJSONStringify
(
b
.
storage_spec
);
}
/**
* Guess if the method is a writer or a reader.
*
* @param {String} method The method name
* @return {String} "writer", "reader" or "unknown"
*/
function
methodType
(
method
)
{
switch
(
method
)
{
case
"
post
"
:
case
"
put
"
:
case
"
putAttachment
"
:
case
"
remove
"
:
case
"
removeAttachment
"
:
case
"
repair
"
:
return
'
writer
'
;
case
"
get
"
:
case
"
getAttachment
"
:
case
"
allDocs
"
:
case
"
check
"
:
return
'
reader
'
;
default
:
return
'
unknown
'
;
}
}
/**
* Compare two jobs and test if they are writers
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
areWriters
(
a
,
b
)
{
return
methodType
(
a
.
method
)
===
'
writer
'
&&
methodType
(
b
.
method
)
===
'
writer
'
;
}
/**
* Compare two jobs and test if they are readers
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
areReaders
(
a
,
b
)
{
return
methodType
(
a
.
method
)
===
'
reader
'
&&
methodType
(
b
.
method
)
===
'
reader
'
;
}
/**
* Compare two jobs and test if their methods are the same
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
sameMethod
(
a
,
b
)
{
return
a
.
method
===
b
.
method
;
}
/**
* Compare two jobs and test if their document ids are the same
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
sameDocumentId
(
a
,
b
)
{
return
a
.
kwargs
.
_id
===
b
.
kwargs
.
_id
;
}
/**
* Compare two jobs and test if their kwargs are equal
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
sameParameters
(
a
,
b
)
{
return
uniqueJSONStringify
(
a
.
kwargs
)
===
uniqueJSONStringify
(
b
.
kwargs
);
}
/**
* Compare two jobs and test if their options are equal
*
* @param {Object} a The first job to compare
* @param {Object} b The second job to compare
* @return {Boolean} True if equal, else false
*/
function
sameOptions
(
a
,
b
)
{
return
uniqueJSONStringify
(
a
.
options
)
===
uniqueJSONStringify
(
b
.
options
);
}
defaults
.
job_rule_actions
=
{
"
sameStorageDescription
"
:
sameStorageDescription
,
"
areWriters
"
:
areWriters
,
"
areReaders
"
:
areReaders
,
"
sameMethod
"
:
sameMethod
,
"
sameDocumentId
"
:
sameDocumentId
,
"
sameParameters
"
:
sameParameters
,
"
sameOptions
"
:
sameOptions
};
}());
src/jio/features/jobChecker.js
0 → 100644
View file @
5260fbb8
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true, unparam: true */
/*global arrayInsert, indexOf, deepClone */
// creates
// - some defaults job rule actions
function
enableJobChecker
(
jio
,
shared
,
options
)
{
// dependencies
// - shared.job_queue JobWorkspace
// creates
// - shared.job_rules Array
// uses 'job' events
shared
.
job_check_method_names
=
[
undefined
,
"
ok
"
,
"
wait
"
,
"
update
"
,
"
deny
"
];
function
addJobRule
(
job_rule
)
{
var
i
,
old_position
,
before_position
,
after_position
;
// job_rule = {
// code_name: string
// conditions: [string, ...]
// action: 'wait',
// after: code_name
// before: code_name
// }
if
(
typeof
job_rule
!==
'
object
'
||
job_rule
===
null
)
{
// wrong job rule
return
;
}
if
(
typeof
job_rule
.
code_name
!==
'
string
'
)
{
// wrong code name
return
;
}
if
(
!
Array
.
isArray
(
job_rule
.
conditions
))
{
// wrong conditions
return
;
}
if
(
indexOf
(
job_rule
.
action
,
shared
.
job_check_method_names
)
===
-
1
)
{
// wrong action
return
;
}
if
(
typeof
job_rule
.
after
!==
'
string
'
)
{
job_rule
.
after
=
''
;
}
if
(
typeof
job_rule
.
before
!==
'
string
'
)
{
job_rule
.
before
=
''
;
}
for
(
i
=
0
;
i
<
shared
.
job_rules
.
length
;
i
+=
1
)
{
if
(
shared
.
job_rules
[
i
].
code_name
===
job_rule
.
after
)
{
after_position
=
i
+
1
;
}
if
(
shared
.
job_rules
[
i
].
code_name
===
job_rule
.
before
)
{
before_position
=
i
;
}
if
(
shared
.
job_rules
[
i
].
code_name
===
job_rule
.
code_name
)
{
old_position
=
i
;
}
}
job_rule
=
{
"
code_name
"
:
job_rule
.
code_name
,
"
conditions
"
:
job_rule
.
conditions
,
"
action
"
:
job_rule
.
action
||
"
ok
"
};
if
(
before_position
===
undefined
)
{
before_position
=
shared
.
job_rules
.
length
;
}
if
(
after_position
>
before_position
)
{
before_position
=
undefined
;
}
if
(
job_rule
.
action
!==
"
ok
"
&&
before_position
!==
undefined
)
{
arrayInsert
(
shared
.
job_rules
,
before_position
,
job_rule
);
}
if
(
old_position
!==
undefined
)
{
if
(
old_position
>=
before_position
)
{
old_position
+=
1
;
}
shared
.
job_rules
.
splice
(
old_position
,
1
);
}
}
if
(
options
.
job_management
!==
false
)
{
shared
.
job_rules
=
[{
"
code_name
"
:
"
readers update
"
,
"
conditions
"
:
[
"
sameStorageDescription
"
,
"
areReaders
"
,
"
sameMethod
"
,
"
sameParameters
"
,
"
sameOptions
"
],
"
action
"
:
"
update
"
},
{
"
code_name
"
:
"
writers update
"
,
"
conditions
"
:
[
"
sameStorageDescription
"
,
"
areWriters
"
,
"
sameMethod
"
,
"
sameParameters
"
],
"
action
"
:
"
update
"
},
{
"
code_name
"
:
"
writers wait
"
,
"
conditions
"
:
[
"
sameStorageDescription
"
,
"
areWriters
"
,
"
sameDocumentId
"
],
"
action
"
:
"
wait
"
}];
var
i
;
if
(
Array
.
isArray
(
options
.
job_rules
))
{
for
(
i
=
0
;
i
<
options
.
job_rules
.
length
;
i
+=
1
)
{
addJobRule
(
deepClone
(
options
.
job_rules
[
i
]));
}
}
shared
.
on
(
'
job
'
,
function
(
param
)
{
// XXX
return
;
});
}
jio
.
jobRules
=
function
()
{
return
deepClone
(
shared
.
job_rules
);
};
}
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