mirror of https://github.com/MISP/MISP
commit
131f2cbf2e
|
@ -185,79 +185,81 @@ 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);
|
||||
}
|
||||
|
||||
public function enqueueFeed() {
|
||||
public function enqueueFeedFetch() {
|
||||
$timestamp = $this->args[0];
|
||||
$userId = $this->args[1];
|
||||
$taskId = $this->args[2];
|
||||
// action options:
|
||||
// 0 = pull
|
||||
// 1 = cache
|
||||
$action = $this->args[3];
|
||||
$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', 'enqueueFeed', $userId, $taskId, $action);
|
||||
if ($task['Task']['timer'] > 0) $this->Task->reQueue($task, 'default', 'ServerShell', 'enqueueFeedFetch', $userId, $taskId);
|
||||
$user = $this->User->getAuthUser($userId);
|
||||
$failCount = 0;
|
||||
if ($action == 0) {
|
||||
$feeds = $this->Feed->find('all', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('enabled' => true)
|
||||
));
|
||||
foreach ($feeds as $k => $feed) {
|
||||
$this->Job->create();
|
||||
$data = array(
|
||||
'worker' => 'default',
|
||||
'job_type' => 'feed_pull',
|
||||
'job_input' => 'Feed: ' . $feed['Feed']['id'],
|
||||
'retries' => 0,
|
||||
'org' => $user['Organisation']['name'],
|
||||
'org_id' => $user['org_id'],
|
||||
'process_id' => 'Part of scheduled feed pull',
|
||||
'message' => 'Pulling.',
|
||||
);
|
||||
$this->Job->save($data);
|
||||
$jobId = $this->Job->id;
|
||||
$result = $this->Feed->downloadFromFeedInitiator($feed['Feed']['id'], $user, $jobId);
|
||||
$this->Job->save(array(
|
||||
'message' => 'Job done.',
|
||||
'progress' => 100,
|
||||
'status' => 4
|
||||
));
|
||||
if ($result !== true) {
|
||||
$this->Job->saveField('message', 'Could not pull feed.');
|
||||
$failCount++;
|
||||
}
|
||||
}
|
||||
$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));
|
||||
} else {
|
||||
$this->Job->create();
|
||||
$data = array(
|
||||
'worker' => 'default',
|
||||
'job_type' => 'feed_cache',
|
||||
'retries' => 0,
|
||||
'org' => $user['Organisation']['name'],
|
||||
'org_id' => $user['org_id'],
|
||||
'process_id' => 'Part of scheduled feed caching',
|
||||
'message' => 'Caching.',
|
||||
);
|
||||
$this->Job->save($data);
|
||||
$jobId = $this->Job->id;
|
||||
$result = $this->Feed->cacheFeedInitiator($user, $jobId, 'all');
|
||||
$this->Job->save(array(
|
||||
'message' => 'Job done.',
|
||||
'progress' => 100,
|
||||
'status' => 4
|
||||
));
|
||||
$this->Task->id = $task['Task']['id'];
|
||||
$this->Task->saveField('message', 'Job completed at ' . date('d/m/Y - H:i:s'));
|
||||
}
|
||||
$feeds = $this->Feed->find('all', array(
|
||||
'recursive' => -1,
|
||||
'conditions' => array('enabled' => true)
|
||||
));
|
||||
foreach ($feeds as $k => $feed) {
|
||||
$this->Job->create();
|
||||
$data = array(
|
||||
'worker' => 'default',
|
||||
'job_type' => 'feed_fetch',
|
||||
'job_input' => 'Feed: ' . $feed['Feed']['id'],
|
||||
'retries' => 0,
|
||||
'org' => $user['Organisation']['name'],
|
||||
'org_id' => $user['org_id'],
|
||||
'process_id' => 'Part of scheduled feed fetch',
|
||||
'message' => 'Pulling.',
|
||||
);
|
||||
$this->Job->save($data);
|
||||
$jobId = $this->Job->id;
|
||||
$result = $this->Feed->downloadFromFeedInitiator($feed['Feed']['id'], $user, $jobId);
|
||||
$this->Job->save(array(
|
||||
'message' => 'Job done.',
|
||||
'progress' => 100,
|
||||
'status' => 4
|
||||
));
|
||||
if ($result !== true) {
|
||||
$this->Job->saveField('message', 'Could not fetch feed.');
|
||||
$failCount++;
|
||||
}
|
||||
}
|
||||
$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));
|
||||
}
|
||||
|
||||
|
||||
|
||||
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();
|
||||
$data = array(
|
||||
'worker' => 'default',
|
||||
'job_type' => 'feed_cache',
|
||||
'retries' => 0,
|
||||
'org' => $user['Organisation']['name'],
|
||||
'org_id' => $user['org_id'],
|
||||
'process_id' => 'Part of scheduled feed caching',
|
||||
'message' => 'Caching.',
|
||||
);
|
||||
$this->Job->save($data);
|
||||
$jobId = $this->Job->id;
|
||||
$result = $this->Feed->cacheFeedInitiator($user, $jobId, 'all');
|
||||
$this->Job->save(array(
|
||||
'message' => 'Job done.',
|
||||
'progress' => 100,
|
||||
'status' => 4
|
||||
));
|
||||
$this->Task->id = $task['Task']['id'];
|
||||
$this->Task->saveField('message', 'Job completed at ' . date('d/m/Y - H:i:s'));
|
||||
}
|
||||
|
||||
public function enqueuePush() {
|
||||
$timestamp = $this->args[0];
|
||||
|
|
|
@ -122,11 +122,17 @@ class TasksController extends AppController {
|
|||
}
|
||||
|
||||
private function _feedScheduler($timestamp, $id, $type) {
|
||||
if ($type == 1){
|
||||
$action = 'enqueueFeedCache';
|
||||
}
|
||||
else {
|
||||
$action = 'enqueueFeedFetch';
|
||||
}
|
||||
$process_id = CakeResque::enqueueAt(
|
||||
$timestamp,
|
||||
'default',
|
||||
'ServerShell',
|
||||
array('enqueueFeed', $timestamp, $this->Auth->user('id'), $id, $type),
|
||||
array($action, $timestamp, $this->Auth->user('id'), $id),
|
||||
true
|
||||
);
|
||||
$this->Task->id = $id;
|
||||
|
|
|
@ -42,8 +42,8 @@ class Task extends AppModel {
|
|||
'next_execution_time' => 1391601600,
|
||||
'message' => 'Not scheduled yet.'
|
||||
),
|
||||
'pull_feeds' => array(
|
||||
'type' => 'pull_feeds',
|
||||
'fetch_feeds' => array(
|
||||
'type' => 'fetch_feeds',
|
||||
'timer' => 0,
|
||||
'scheduled_time' => '12:00',
|
||||
'process_id' => '',
|
||||
|
|
Loading…
Reference in New Issue