mirror of https://github.com/MISP/MISP
Timing for rescheduling of tasks changed slightly
- The rescheduling now happens before the task is executed - this way a failed job will not prevent the rescheduling of the next execution timepull/516/head
parent
8b3081a06b
commit
b36c0da66a
|
@ -1 +1 @@
|
|||
{"major":2, "minor":3, "hotfix":73}
|
||||
{"major":2, "minor":3, "hotfix":74}
|
||||
|
|
|
@ -323,10 +323,11 @@ class EventShell extends AppShell
|
|||
// If the next execution time and the timestamp don't match, it means that this task is no longer valid as the time for the execution has since being scheduled
|
||||
// been updated.
|
||||
if ($task['Task']['next_execution_time'] != $timestamp) return;
|
||||
$task['Task']['scheduled_time'] = date('H:i', $task['Task']['next_execution_time']);
|
||||
$this->Task->save($task);
|
||||
|
||||
$orgs = $this->User->getOrgs();
|
||||
|
||||
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'cache', 'EventShell', 'enqueueCaching', false, false);
|
||||
|
||||
// Queue a set of exports for admins. This "ADMIN" organisation. The organisation of the admin users doesn't actually matter, it is only used to indentify
|
||||
// the special cache files containing all events
|
||||
$i = 0;
|
||||
|
@ -338,27 +339,8 @@ class EventShell extends AppShell
|
|||
$this->Job->cache($k, true, 'ADMIN', 'All events.', 'ADMIN');
|
||||
$i++;
|
||||
}
|
||||
$task['Task']['message'] = $i . ' jobs started at ' . date('d/m/Y - H:i:s') . '.';
|
||||
if ($task['Task']['timer'] > 0) {
|
||||
$time = time();
|
||||
// Keep adding the timer's time interval until we get a date that is in the future! We don't want to keep queuing tasks in the past since they will execute until it catches up.
|
||||
while ($task['Task']['next_execution_time'] < $time) {
|
||||
$task['Task']['next_execution_time'] = strtotime('+' . $task['Task']['timer'] . ' hours', $task['Task']['next_execution_time']);
|
||||
}
|
||||
$task['Task']['scheduled_time'] = $this->Task->breakTime($task['Task']['scheduled_time'], $task['Task']['timer']);
|
||||
$task['Task']['scheduled_time'] = date('H:i', $task['Task']['next_execution_time']);
|
||||
|
||||
// Now that we have figured out when the next execution should happen, it's time to enqueue it.
|
||||
$process_id = CakeResque::enqueueAt(
|
||||
$task['Task']['next_execution_time'],
|
||||
'cache',
|
||||
'EventShell',
|
||||
array('enqueueCaching', $task['Task']['next_execution_time']),
|
||||
true
|
||||
);
|
||||
$task['Task']['job_id'] = $process_id;
|
||||
$this->Task->save($task);
|
||||
}
|
||||
$this->Task->id = $task['Task']['id'];
|
||||
$this->Task->saveField('message', $i . ' job(s) started at ' . date('d/m/Y - H:i:s') . '.');
|
||||
}
|
||||
|
||||
public function publish() {
|
||||
|
|
|
@ -86,6 +86,7 @@ class ServerShell extends AppShell
|
|||
$user = $this->User->read(array('id', 'org', 'email'), $userId);
|
||||
$servers = $this->Server->find('all', array('recursive' => -1, 'conditions' => array('pull' => 1)));
|
||||
$count = count($servers);
|
||||
$failCount = 0;
|
||||
foreach ($servers as $k => $server) {
|
||||
$this->Job->create();
|
||||
$data = array(
|
||||
|
@ -99,6 +100,9 @@ class ServerShell extends AppShell
|
|||
);
|
||||
$this->Job->save($data);
|
||||
$jobId = $this->Job->id;
|
||||
|
||||
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueuePull', $userId, $taskId);
|
||||
|
||||
App::uses('SyncTool', 'Tools');
|
||||
$syncTool = new SyncTool();
|
||||
$result = $this->Server->pull($user['User'], $server['Server']['id'], 'full', $server, $jobId);
|
||||
|
@ -124,29 +128,11 @@ class ServerShell extends AppShell
|
|||
break;
|
||||
|
||||
}
|
||||
$failCount++;
|
||||
}
|
||||
}
|
||||
$task['Task']['message'] = count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.';
|
||||
if ($task['Task']['timer'] > 0) {
|
||||
$time = time();
|
||||
// Keep adding the timer's time interval until we get a date that is in the future! We don't want to keep queuing tasks in the past since they will execute until it catches up.
|
||||
while ($task['Task']['next_execution_time'] < $time) {
|
||||
$task['Task']['next_execution_time'] = strtotime('+' . $task['Task']['timer'] . ' hours', $task['Task']['next_execution_time']);
|
||||
}
|
||||
$task['Task']['scheduled_time'] = $this->Task->breakTime($task['Task']['scheduled_time'], $task['Task']['timer']);
|
||||
$task['Task']['scheduled_time'] = date('H:i', $task['Task']['next_execution_time']);
|
||||
|
||||
// Now that we have figured out when the next execution should happen, it's time to enqueue it.
|
||||
$process_id = CakeResque::enqueueAt(
|
||||
$task['Task']['next_execution_time'],
|
||||
'default',
|
||||
'ServerShell',
|
||||
array('enqueuePull', $task['Task']['next_execution_time'],$userId, $taskId),
|
||||
true
|
||||
);
|
||||
$task['Task']['job_id'] = $process_id;
|
||||
$this->Task->save($task);
|
||||
}
|
||||
$this->Task->id = $task['Task']['id'];
|
||||
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . $count);
|
||||
}
|
||||
|
||||
public function enqueuePush() {
|
||||
|
@ -159,6 +145,8 @@ class ServerShell extends AppShell
|
|||
if ($timestamp != $task['Task']['next_execution_time']) {
|
||||
return;
|
||||
}
|
||||
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueuePush', $userId, $taskId);
|
||||
|
||||
$this->User->recursive = -1;
|
||||
$user = $this->User->read(array('id', 'org', 'email'), $userId);
|
||||
$servers = $this->Server->find('all', array('recursive' => -1, 'conditions' => array('push' => 1)));
|
||||
|
@ -181,26 +169,7 @@ class ServerShell extends AppShell
|
|||
$HttpSocket = $syncTool->setupHttpSocket($server);
|
||||
$result = $this->Server->push($server['Server']['id'], 'full', $jobId, $HttpSocket, $user['User']['email']);
|
||||
}
|
||||
$task['Task']['message'] = count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.';
|
||||
if ($task['Task']['timer'] > 0) {
|
||||
$time = time();
|
||||
// Keep adding the timer's time interval until we get a date that is in the future! We don't want to keep queuing tasks in the past since they will execute until it catches up.
|
||||
while ($task['Task']['next_execution_time'] < $time) {
|
||||
$task['Task']['next_execution_time'] = strtotime('+' . $task['Task']['timer'] . ' hours', $task['Task']['next_execution_time']);
|
||||
}
|
||||
$task['Task']['scheduled_time'] = $this->Task->breakTime($task['Task']['scheduled_time'], $task['Task']['timer']);
|
||||
$task['Task']['scheduled_time'] = date('H:i', $task['Task']['next_execution_time']);
|
||||
|
||||
// Now that we have figured out when the next execution should happen, it's time to enqueue it.
|
||||
$process_id = CakeResque::enqueueAt(
|
||||
$task['Task']['next_execution_time'],
|
||||
'default',
|
||||
'ServerShell',
|
||||
array('enqueuePush', $task['Task']['next_execution_time'], $taskId, $org, $userId),
|
||||
true
|
||||
);
|
||||
$task['Task']['job_id'] = $process_id;
|
||||
$this->Task->save($task);
|
||||
}
|
||||
$this->Task->id = $task['Task']['id'];
|
||||
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '.');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,4 +24,26 @@ class Task extends AppModel {
|
|||
if ($temp[0] > 23) $temp[0] = $temp[0] - 24;
|
||||
return $temp[0] . ':' . $temp[1];
|
||||
}
|
||||
|
||||
public function reQueue($task, $worker, $shell, $action, $userId, $taskId) {
|
||||
$time = time();
|
||||
// Keep adding the timer's time interval until we get a date that is in the future! We don't want to keep queuing tasks in the past since they will execute until it catches up.
|
||||
while ($task['Task']['next_execution_time'] < $time) {
|
||||
$task['Task']['next_execution_time'] = strtotime('+' . $task['Task']['timer'] . ' hours', $task['Task']['next_execution_time']);
|
||||
}
|
||||
$task['Task']['scheduled_time'] = $this->breakTime($task['Task']['scheduled_time'], $task['Task']['timer']);
|
||||
$task['Task']['scheduled_time'] = date('H:i', $task['Task']['next_execution_time']);
|
||||
|
||||
// Now that we have figured out when the next execution should happen, it's time to enqueue it.
|
||||
$process_id = CakeResque::enqueueAt(
|
||||
$task['Task']['next_execution_time'],
|
||||
$worker,
|
||||
$shell,
|
||||
array($action, $task['Task']['next_execution_time'],$userId, $taskId),
|
||||
true
|
||||
);
|
||||
$task['Task']['job_id'] = $process_id;
|
||||
$this->id = $task['Task']['id'];
|
||||
$this->save($task);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue