mirror of https://github.com/MISP/MISP
commit
131f2cbf2e
|
@ -185,22 +185,17 @@ class ServerShell extends AppShell
|
||||||
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . $count);
|
$this->Task->saveField('message', count($servers) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . $count);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function enqueueFeed() {
|
public function enqueueFeedFetch() {
|
||||||
$timestamp = $this->args[0];
|
$timestamp = $this->args[0];
|
||||||
$userId = $this->args[1];
|
$userId = $this->args[1];
|
||||||
$taskId = $this->args[2];
|
$taskId = $this->args[2];
|
||||||
// action options:
|
|
||||||
// 0 = pull
|
|
||||||
// 1 = cache
|
|
||||||
$action = $this->args[3];
|
|
||||||
$task = $this->Task->read(null, $taskId);
|
$task = $this->Task->read(null, $taskId);
|
||||||
if ($timestamp != $task['Task']['next_execution_time']) {
|
if ($timestamp != $task['Task']['next_execution_time']) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueueFeed', $userId, $taskId, $action);
|
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueueFeedFetch', $userId, $taskId);
|
||||||
$user = $this->User->getAuthUser($userId);
|
$user = $this->User->getAuthUser($userId);
|
||||||
$failCount = 0;
|
$failCount = 0;
|
||||||
if ($action == 0) {
|
|
||||||
$feeds = $this->Feed->find('all', array(
|
$feeds = $this->Feed->find('all', array(
|
||||||
'recursive' => -1,
|
'recursive' => -1,
|
||||||
'conditions' => array('enabled' => true)
|
'conditions' => array('enabled' => true)
|
||||||
|
@ -209,12 +204,12 @@ class ServerShell extends AppShell
|
||||||
$this->Job->create();
|
$this->Job->create();
|
||||||
$data = array(
|
$data = array(
|
||||||
'worker' => 'default',
|
'worker' => 'default',
|
||||||
'job_type' => 'feed_pull',
|
'job_type' => 'feed_fetch',
|
||||||
'job_input' => 'Feed: ' . $feed['Feed']['id'],
|
'job_input' => 'Feed: ' . $feed['Feed']['id'],
|
||||||
'retries' => 0,
|
'retries' => 0,
|
||||||
'org' => $user['Organisation']['name'],
|
'org' => $user['Organisation']['name'],
|
||||||
'org_id' => $user['org_id'],
|
'org_id' => $user['org_id'],
|
||||||
'process_id' => 'Part of scheduled feed pull',
|
'process_id' => 'Part of scheduled feed fetch',
|
||||||
'message' => 'Pulling.',
|
'message' => 'Pulling.',
|
||||||
);
|
);
|
||||||
$this->Job->save($data);
|
$this->Job->save($data);
|
||||||
|
@ -226,13 +221,24 @@ class ServerShell extends AppShell
|
||||||
'status' => 4
|
'status' => 4
|
||||||
));
|
));
|
||||||
if ($result !== true) {
|
if ($result !== true) {
|
||||||
$this->Job->saveField('message', 'Could not pull feed.');
|
$this->Job->saveField('message', 'Could not fetch feed.');
|
||||||
$failCount++;
|
$failCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$this->Task->id = $task['Task']['id'];
|
$this->Task->id = $task['Task']['id'];
|
||||||
$this->Task->saveField('message', count($feeds) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . count($feeds));
|
$this->Task->saveField('message', count($feeds) . ' job(s) completed at ' . date('d/m/Y - H:i:s') . '. Failed jobs: ' . $failCount . '/' . count($feeds));
|
||||||
} else {
|
}
|
||||||
|
|
||||||
|
public function enqueueFeedCache() {
|
||||||
|
$timestamp = $this->args[0];
|
||||||
|
$userId = $this->args[1];
|
||||||
|
$taskId = $this->args[2];
|
||||||
|
$task = $this->Task->read(null, $taskId);
|
||||||
|
if ($timestamp != $task['Task']['next_execution_time']) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueueFeedCache', $userId, $taskId);
|
||||||
|
$user = $this->User->getAuthUser($userId);
|
||||||
$this->Job->create();
|
$this->Job->create();
|
||||||
$data = array(
|
$data = array(
|
||||||
'worker' => 'default',
|
'worker' => 'default',
|
||||||
|
@ -254,10 +260,6 @@ class ServerShell extends AppShell
|
||||||
$this->Task->id = $task['Task']['id'];
|
$this->Task->id = $task['Task']['id'];
|
||||||
$this->Task->saveField('message', 'Job completed at ' . date('d/m/Y - H:i:s'));
|
$this->Task->saveField('message', 'Job completed at ' . date('d/m/Y - H:i:s'));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function enqueuePush() {
|
public function enqueuePush() {
|
||||||
$timestamp = $this->args[0];
|
$timestamp = $this->args[0];
|
||||||
|
|
|
@ -122,11 +122,17 @@ class TasksController extends AppController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private function _feedScheduler($timestamp, $id, $type) {
|
private function _feedScheduler($timestamp, $id, $type) {
|
||||||
|
if ($type == 1){
|
||||||
|
$action = 'enqueueFeedCache';
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$action = 'enqueueFeedFetch';
|
||||||
|
}
|
||||||
$process_id = CakeResque::enqueueAt(
|
$process_id = CakeResque::enqueueAt(
|
||||||
$timestamp,
|
$timestamp,
|
||||||
'default',
|
'default',
|
||||||
'ServerShell',
|
'ServerShell',
|
||||||
array('enqueueFeed', $timestamp, $this->Auth->user('id'), $id, $type),
|
array($action, $timestamp, $this->Auth->user('id'), $id),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
$this->Task->id = $id;
|
$this->Task->id = $id;
|
||||||
|
|
|
@ -42,8 +42,8 @@ class Task extends AppModel {
|
||||||
'next_execution_time' => 1391601600,
|
'next_execution_time' => 1391601600,
|
||||||
'message' => 'Not scheduled yet.'
|
'message' => 'Not scheduled yet.'
|
||||||
),
|
),
|
||||||
'pull_feeds' => array(
|
'fetch_feeds' => array(
|
||||||
'type' => 'pull_feeds',
|
'type' => 'fetch_feeds',
|
||||||
'timer' => 0,
|
'timer' => 0,
|
||||||
'scheduled_time' => '12:00',
|
'scheduled_time' => '12:00',
|
||||||
'process_id' => '',
|
'process_id' => '',
|
||||||
|
|
Loading…
Reference in New Issue