Commit e3bf3e8c authored by Tristan Cavelier's avatar Tristan Cavelier

job checker upgraded to deny jobs and to check single job

parent 6b39103c
...@@ -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,6 +150,22 @@ function enableJobChecker(jio, shared, options) { ...@@ -137,6 +150,22 @@ 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) {
if (shared.job_rules[i].single) {
// no browse
if (
jobsRespectConditions(
job,
undefined,
shared.job_rules[i].conditions
)
) {
shared.job_rule_actions[shared.job_rules[i].action](
undefined,
job
);
return;
}
} else {
// browsing jobs // browsing jobs
for (j = 0; j < shared.jobs.length; j += 1) { for (j = 0; j < shared.jobs.length; j += 1) {
if (shared.jobs[j] !== job) { if (shared.jobs[j] !== job) {
...@@ -158,6 +187,7 @@ function enableJobChecker(jio, shared, options) { ...@@ -158,6 +187,7 @@ function enableJobChecker(jio, shared, options) {
} }
} }
} }
}
if (options.job_management !== false) { if (options.job_management !== false) {
...@@ -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