Commit cebe0585 authored by Tristan Cavelier's avatar Tristan Cavelier

job checker upgraded to deny jobs and to check single job

parent d8ec1e42
...@@ -44,8 +44,12 @@ function enableJobChecker(jio, shared, options) { ...@@ -44,8 +44,12 @@ function enableJobChecker(jio, shared, options) {
new_job.modified = new Date(); new_job.modified = new Date();
}, },
deny: function (original_job, new_job) { deny: function (original_job, new_job) {
// XXX new_job.state = 'running';
return; new_job.command.reject(
'precondition_failed',
'command denied',
'Command rejected by the job checker.'
);
} }
}; };
...@@ -70,10 +74,18 @@ function enableJobChecker(jio, shared, options) { ...@@ -70,10 +74,18 @@ function enableJobChecker(jio, shared, options) {
// wrong conditions // wrong conditions
return; return;
} }
if (job_rule.single !== undefined && typeof job_rule.single !== 'boolean') {
// wrong single property
return;
}
if (indexOf(job_rule.action, shared.job_rule_action_names) === -1) { if (indexOf(job_rule.action, shared.job_rule_action_names) === -1) {
// wrong action // wrong action
return; return;
} }
if (job_rule.action !== 'deny' && job_rule.single === true) {
// only 'deny' action doesn't require original_job parameter
return;
}
if (typeof job_rule.after !== 'string') { if (typeof job_rule.after !== 'string') {
job_rule.after = ''; job_rule.after = '';
...@@ -97,6 +109,7 @@ function enableJobChecker(jio, shared, options) { ...@@ -97,6 +109,7 @@ function enableJobChecker(jio, shared, options) {
job_rule = { job_rule = {
"code_name": job_rule.code_name, "code_name": job_rule.code_name,
"conditions": job_rule.conditions, "conditions": job_rule.conditions,
"single": job_rule.single || false,
"action": job_rule.action || "ok" "action": job_rule.action || "ok"
}; };
...@@ -137,21 +150,38 @@ function enableJobChecker(jio, shared, options) { ...@@ -137,21 +150,38 @@ function enableJobChecker(jio, shared, options) {
if (job.state === 'ready') { if (job.state === 'ready') {
// browsing rules // browsing rules
for (i = 0; i < shared.job_rules.length; i += 1) { for (i = 0; i < shared.job_rules.length; i += 1) {
// browsing jobs if (shared.job_rules[i].single) {
for (j = 0; j < shared.jobs.length; j += 1) { // no browse
if (shared.jobs[j] !== job) { if (
if ( jobsRespectConditions(
jobsRespectConditions( job,
shared.jobs[j], undefined,
job, shared.job_rules[i].conditions
shared.job_rules[i].conditions )
) ) {
) { shared.job_rule_actions[shared.job_rules[i].action](
shared.job_rule_actions[shared.job_rules[i].action]( undefined,
shared.jobs[j], job
job );
); return;
return; }
} else {
// browsing jobs
for (j = 0; j < shared.jobs.length; j += 1) {
if (shared.jobs[j] !== job) {
if (
jobsRespectConditions(
shared.jobs[j],
job,
shared.job_rules[i].conditions
)
) {
shared.job_rule_actions[shared.job_rules[i].action](
shared.jobs[j],
job
);
return;
}
} }
} }
} }
...@@ -203,4 +233,5 @@ function enableJobChecker(jio, shared, options) { ...@@ -203,4 +233,5 @@ function enableJobChecker(jio, shared, options) {
jio.jobRules = function () { jio.jobRules = function () {
return deepClone(shared.job_rules); return deepClone(shared.job_rules);
}; };
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment