Skip to content

Commit 114301c

Browse files
committed
Allow optional reason for job termination to be provided on CEM api
1 parent c7068b8 commit 114301c

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

api/v1/cem.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,17 @@ public function post() {
150150
$this->setStatusCode(API::STATUS_NUM_JOB_DOES_NOT_EXIST);
151151
throw new Exception('Job does not exist!');
152152
}
153-
if ($job->getStatus() == Define::JOB_STATUS_RUNNING || $job->getStatus() == Define::JOB_STATUS_SCHEDULED
153+
if (!empty($this->request['reason'])) {
154+
// If the client specified a reason for the termination, always set job state to failed and add event containing the message from the client
155+
$reason = $this->request['reason'];
156+
$job->setStatus(Define::JOB_STATUS_FAILED);
157+
Factory::getJobFactory()->update($job);
158+
// Create event
159+
$event = new Event(0, "Job terminated", date('Y-m-d H:i:s'),
160+
"The job with the ID " . $job->getId() . " has terminated. The following reason has been provided by the CEM bootstrapper: " . $reason,
161+
Define::EVENT_NODE, $job->getId(), null, $node->getId());
162+
Factory::getEventFactory()->save($event);
163+
} else if ($job->getStatus() == Define::JOB_STATUS_RUNNING || $job->getStatus() == Define::JOB_STATUS_SCHEDULED
154164
|| $job->getStatus() == Define::JOB_STATUS_SETUP ) {
155165
$job->setStatus(Define::JOB_STATUS_FAILED);
156166
Factory::getJobFactory()->update($job);
@@ -167,7 +177,6 @@ public function post() {
167177
}
168178
$node->setCurrentJob(null);
169179
Factory::getNodeFactory()->update($node);
170-
171180
break;
172181

173182
case(strtolower('nodeStatus')):

0 commit comments

Comments
 (0)