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
282d28d5
Commit
282d28d5
authored
Jan 10, 2013
by
Sven Franck
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
jslint pass jobRules.js
parent
2534a5e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
209 additions
and
183 deletions
+209
-183
src/jio/jobs/jobRules.js
src/jio/jobs/jobRules.js
+209
-183
No files found.
src/jio/jobs/jobRules.js
View file @
282d28d5
var
jobRules
=
(
function
(
spec
)
{
/*jslint indent: 2, maxlen: 80, sloppy: true */
var
that
=
{};
var
jobRules
=
(
function
()
{
// Attributes //
var
that
=
{},
priv
=
{};
var
priv
=
{};
priv
.
compare
=
{};
priv
.
action
=
{};
Object
.
defineProperty
(
that
,
"
eliminate
"
,{
priv
.
compare
=
{};
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
priv
.
action
=
{};
function
()
{
return
'
eliminate
'
;
}
});
Object
.
defineProperty
(
that
,
"
update
"
,{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
()
{
return
'
update
'
;
}
});
Object
.
defineProperty
(
that
,
"
dontAccept
"
,{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
()
{
return
'
dont accept
'
;
}
});
Object
.
defineProperty
(
that
,
"
wait
"
,{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
()
{
return
'
wait
'
;
}
});
Object
.
defineProperty
(
that
,
"
none
"
,{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
()
{
return
'
none
'
;
}
});
that
.
default_action
=
that
.
none
;
that
.
default_compare
=
function
(
job1
,
job2
)
{
return
(
job1
.
getCommand
().
getDocId
()
===
job2
.
getCommand
().
getDocId
()
&&
job1
.
getCommand
().
getDocInfo
(
'
_rev
'
)
===
job2
.
getCommand
().
getDocInfo
(
'
_rev
'
)
&&
job1
.
getCommand
().
getOption
(
'
rev
'
)
===
job2
.
getCommand
().
getOption
(
'
rev
'
)
&&
JSON
.
stringify
(
job1
.
getStorage
().
serialized
())
===
JSON
.
stringify
(
job2
.
getStorage
().
serialized
()));
};
// Methods //
Object
.
defineProperty
(
that
,
"
eliminate
"
,
{
/**
configurable
:
false
,
* Returns an action according the jobs given in parameters.
enumerable
:
false
,
* @method getAction
writable
:
false
,
* @param {object} job1 The already existant job.
value
:
function
()
{
* @param {object} job2 The job to compare with.
return
'
eliminate
'
;
* @return {string} An action string.
}
*/
});
priv
.
getAction
=
function
(
job1
,
job2
)
{
Object
.
defineProperty
(
that
,
"
update
"
,
{
var
j1label
,
j2label
,
j1status
;
configurable
:
false
,
j1label
=
job1
.
getCommand
().
getLabel
();
enumerable
:
false
,
j2label
=
job2
.
getCommand
().
getLabel
();
writable
:
false
,
j1status
=
(
job1
.
getStatus
().
getLabel
()
===
'
on going
'
?
value
:
function
()
{
'
on going
'
:
'
not on going
'
);
return
'
update
'
;
if
(
priv
.
action
[
j1label
]
&&
}
priv
.
action
[
j1label
][
j1status
]
&&
});
priv
.
action
[
j1label
][
j1status
][
j2label
])
{
Object
.
defineProperty
(
that
,
"
dontAccept
"
,
{
return
priv
.
action
[
j1label
][
j1status
][
j2label
](
job1
,
job2
);
configurable
:
false
,
}
else
{
enumerable
:
false
,
return
that
.
default_action
(
job1
,
job2
);
writable
:
false
,
}
value
:
function
()
{
};
return
'
dont accept
'
;
}
});
Object
.
defineProperty
(
that
,
"
wait
"
,
{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
()
{
return
'
wait
'
;
}
});
Object
.
defineProperty
(
that
,
"
none
"
,
{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
()
{
return
'
none
'
;
}
});
that
.
default_action
=
that
.
none
;
that
.
default_compare
=
function
(
job1
,
job2
)
{
return
(
job1
.
getCommand
().
getDocId
()
===
job2
.
getCommand
().
getDocId
()
&&
job1
.
getCommand
().
getDocInfo
(
'
_rev
'
)
===
job2
.
getCommand
().
getDocInfo
(
'
_rev
'
)
&&
job1
.
getCommand
().
getOption
(
'
rev
'
)
===
job2
.
getCommand
().
getOption
(
'
rev
'
)
&&
JSON
.
stringify
(
job1
.
getStorage
().
serialized
())
===
JSON
.
stringify
(
job2
.
getStorage
().
serialized
()));
};
/**
// Methods //
* Checks if the two jobs are comparable.
/**
* @method canCompare
* Returns an action according the jobs given in parameters.
* @param {object} job1 The already existant job.
* @method getAction
* @param {object} job2 The job to compare with.
* @param {object} job1 The already existant job.
* @return {boolean} true if comparable, else false.
* @param {object} job2 The job to compare with.
*/
* @return {string} An action string.
priv
.
canCompare
=
function
(
job1
,
job2
)
{
*/
var
job1label
=
job1
.
getCommand
().
getLabel
(),
priv
.
getAction
=
function
(
job1
,
job2
)
{
job2label
=
job2
.
getCommand
().
getLabel
();
var
j1label
,
j2label
,
j1status
;
if
(
priv
.
compare
[
job1label
]
&&
j1label
=
job1
.
getCommand
().
getLabel
();
priv
.
compare
[
job2label
])
{
j2label
=
job2
.
getCommand
().
getLabel
();
return
priv
.
compare
[
job1label
][
job2label
](
job1
,
job2
);
j1status
=
(
job1
.
getStatus
().
getLabel
()
===
'
on going
'
?
}
else
{
'
on going
'
:
'
not on going
'
);
return
that
.
default_compare
(
job1
,
job2
);
if
(
priv
.
action
[
j1label
]
&&
priv
.
action
[
j1label
][
j1status
]
&&
}
priv
.
action
[
j1label
][
j1status
][
j2label
])
{
};
return
priv
.
action
[
j1label
][
j1status
][
j2label
](
job1
,
job2
);
}
return
that
.
default_action
(
job1
,
job2
);
};
/**
/**
* Returns an action string to show what to do if we want to add a job.
* Checks if the two jobs are comparable.
* @method validateJobAccordingToJob
* @method canCompare
* @param {object} job1 The current job.
* @param {object} job1 The already existant job.
* @param {object} job2 The new job.
* @param {object} job2 The job to compare with.
* @return {string} The action string.
* @return {boolean} true if comparable, else false.
*/
*/
Object
.
defineProperty
(
that
,
"
validateJobAccordingToJob
"
,{
priv
.
canCompare
=
function
(
job1
,
job2
)
{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
var
job1label
=
job1
.
getCommand
().
getLabel
(),
function
(
job1
,
job2
)
{
job2label
=
job2
.
getCommand
().
getLabel
();
if
(
priv
.
canCompare
(
job1
,
job2
))
{
if
(
priv
.
compare
[
job1label
]
&&
priv
.
compare
[
job2label
])
{
return
{
action
:
priv
.
getAction
(
job1
,
job2
),
job
:
job1
};
return
priv
.
compare
[
job1label
][
job2label
](
job1
,
job2
);
}
}
return
{
action
:
that
.
default_action
(
job1
,
job2
),
job
:
job1
};
return
that
.
default_compare
(
job1
,
job2
);
}
};
});
/**
/**
* Adds a rule the action rules.
* Returns an action string to show what to do if we want to add a job.
* @method addActionRule
* @method validateJobAccordingToJob
* @param {string} method1 The action label from the current job.
* @param {object} job1 The current job.
* @param {boolean} ongoing Is this action is on going or not?
* @param {object} job2 The new job.
* @param {string} method2 The action label from the new job.
* @return {string} The action string.
* @param {function} rule The rule that return an action string.
*/
*/
Object
.
defineProperty
(
that
,
"
validateJobAccordingToJob
"
,
{
Object
.
defineProperty
(
that
,
"
addActionRule
"
,{
configurable
:
false
,
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
enumerable
:
false
,
function
(
method1
,
ongoing
,
method2
,
rule
)
{
writable
:
false
,
var
ongoing_s
=
(
ongoing
?
'
on going
'
:
'
not on going
'
);
value
:
function
(
job1
,
job2
)
{
priv
.
action
[
method1
]
=
priv
.
action
[
method1
]
||
{};
if
(
priv
.
canCompare
(
job1
,
job2
))
{
priv
.
action
[
method1
][
ongoing_s
]
=
return
{
priv
.
action
[
method1
][
ongoing_s
]
||
{};
action
:
priv
.
getAction
(
job1
,
job2
),
priv
.
action
[
method1
][
ongoing_s
][
method2
]
=
rule
;
job
:
job1
}
};
});
}
return
{
action
:
that
.
default_action
(
job1
,
job2
),
job
:
job1
};
}
});
/**
/**
* Adds a rule the compare rules.
* Adds a rule the action rules.
* @method addCompareRule
* @method addActionRule
* @param {string} method1 The action label from the current job.
* @param {string} method1 The action label from the current job.
* @param {string} method2 The action label from the new job.
* @param {boolean} ongoing Is this action is on going or not?
* @param {function} rule The rule that return a boolean
* @param {string} method2 The action label from the new job.
* - true if job1 and job2 can be compared, else false.
* @param {function} rule The rule that return an action string.
*/
*/
Object
.
defineProperty
(
that
,
"
addCompareRule
"
,{
Object
.
defineProperty
(
that
,
"
addActionRule
"
,
{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
configurable
:
false
,
function
(
method1
,
method2
,
rule
)
{
enumerable
:
false
,
priv
.
compare
[
method1
]
=
priv
.
compare
[
method1
]
||
{};
writable
:
false
,
priv
.
compare
[
method1
][
method2
]
=
rule
;
value
:
function
(
method1
,
ongoing
,
method2
,
rule
)
{
}
var
ongoing_s
=
(
ongoing
?
'
on going
'
:
'
not on going
'
);
});
priv
.
action
[
method1
]
=
priv
.
action
[
method1
]
||
{};
priv
.
action
[
method1
][
ongoing_s
]
=
priv
.
action
[
method1
][
ongoing_s
]
||
{};
priv
.
action
[
method1
][
ongoing_s
][
method2
]
=
rule
;
}
});
////////////////////////////////////////////////////////////////////////////
/**
// Adding some rules
* Adds a rule the compare rules.
/*
* @method addCompareRule
* @param {string} method1 The action label from the current job.
* @param {string} method2 The action label from the new job.
* @param {function} rule The rule that return a boolean
* - true if job1 and job2 can be compared, else false.
*/
Object
.
defineProperty
(
that
,
"
addCompareRule
"
,
{
configurable
:
false
,
enumerable
:
false
,
writable
:
false
,
value
:
function
(
method1
,
method2
,
rule
)
{
priv
.
compare
[
method1
]
=
priv
.
compare
[
method1
]
||
{};
priv
.
compare
[
method1
][
method2
]
=
rule
;
}
});
////////////////////////////////////////////////////////////////////////////
// Adding some rules
/*
LEGEND:
LEGEND:
- s: storage
- s: storage
- m: method
- m: method
...
@@ -182,63 +208,63 @@ var jobRules = (function(spec) {
...
@@ -182,63 +208,63 @@ var jobRules = (function(spec) {
For more information, see documentation
For more information, see documentation
*/
*/
that
.
addActionRule
(
'
post
'
,
true
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
post
'
,
true
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
post
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
false
,
'
post
'
,
that
.
update
);
that
.
addActionRule
(
'
post
'
,
false
,
'
post
'
,
that
.
update
);
that
.
addActionRule
(
'
post
'
,
false
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
false
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
false
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
false
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
false
,
'
remove
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
post
'
,
false
,
'
remove
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
post
'
,
false
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
post
'
,
false
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
put
'
,
true
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
put
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
false
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
put
'
,
false
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
put
'
,
false
,
'
put
'
,
that
.
update
);
that
.
addActionRule
(
'
put
'
,
false
,
'
put
'
,
that
.
update
);
that
.
addActionRule
(
'
put
'
,
false
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
false
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
false
,
'
remove
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
put
'
,
false
,
'
remove
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
put
'
,
false
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
put
'
,
false
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
post
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
post
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
get
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
get
'
,
true
,
'
get
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
get
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
post
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
post
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
get
'
,
that
.
update
);
that
.
addActionRule
(
'
get
'
,
false
,
'
get
'
,
that
.
update
);
that
.
addActionRule
(
'
get
'
,
false
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
get
'
,
false
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
post
'
,
that
.
wait
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
post
'
,
that
.
wait
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
get
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
get
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
remove
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
remove
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
putAttachment
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
true
,
'
putAttachment
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
post
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
post
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
put
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
put
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
get
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
get
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
remove
'
,
that
.
update
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
remove
'
,
that
.
update
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
putAttachment
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
remove
'
,
false
,
'
putAttachment
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
allDocs
'
,
true
,
'
allDocs
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
allDocs
'
,
true
,
'
allDocs
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
allDocs
'
,
false
,
'
allDocs
'
,
that
.
update
);
that
.
addActionRule
(
'
allDocs
'
,
false
,
'
allDocs
'
,
that
.
update
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
remove
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
true
,
'
putAttachment
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
post
'
,
that
.
dontAccept
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
put
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
get
'
,
that
.
wait
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
remove
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
remove
'
,
that
.
eliminate
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
putAttachment
'
,
that
.
update
);
that
.
addActionRule
(
'
putAttachment
'
,
false
,
'
putAttachment
'
,
that
.
update
);
// end adding rules
// end adding rules
////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
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