chg: use new bg jobs tool in feeds controller

pull/7939/head
Luciano Righetti 2021-11-02 11:10:01 +01:00
parent 6280311206
commit 2164746aa6
1 changed files with 66 additions and 54 deletions

View File

@ -488,26 +488,30 @@ class FeedsController extends AppController
} }
} }
if (Configure::read('MISP.background_jobs')) { if (Configure::read('MISP.background_jobs')) {
$this->loadModel('Job');
$this->Job->create(); /** @var Job $job */
$data = array( $job = ClassRegistry::init('Job');
'worker' => 'default', $jobId = $job->createJob(
'job_type' => 'fetch_feeds', $this->Auth->user(),
'job_input' => 'Feed: ' . $feedId, Job::WORKER_DEFAULT,
'status' => 0, 'fetch_feeds',
'retries' => 0, 'Feed: ' . $feedId,
'org' => $this->Auth->user('Organisation')['name'], __('Starting fetch from Feed.')
'message' => __('Starting fetch from Feed.'),
); );
$this->Job->save($data);
$jobId = $this->Job->id; $this->Feed->getBackgroundJobsTool()->enqueue(
$process_id = CakeResque::enqueue( BackgroundJobsTool::DEFAULT_QUEUE,
'default', BackgroundJobsTool::CMD_SERVER,
'ServerShell', [
array('fetchFeed', $this->Auth->user('id'), $feedId, $jobId), 'fetchFeed',
true $this->Auth->user('id'),
$feedId,
$jobId
],
true,
$jobId
); );
$this->Job->saveField('process_id', $process_id);
$message = __('Pull queued for background execution.'); $message = __('Pull queued for background execution.');
} else { } else {
$result = $this->Feed->downloadFromFeedInitiator($feedId, $this->Auth->user()); $result = $this->Feed->downloadFromFeedInitiator($feedId, $this->Auth->user());
@ -554,26 +558,30 @@ class FeedsController extends AppController
continue; continue;
} }
if (Configure::read('MISP.background_jobs')) { if (Configure::read('MISP.background_jobs')) {
$this->loadModel('Job');
$this->Job->create(); /** @var Job $job */
$data = array( $job = ClassRegistry::init('Job');
'worker' => 'default', $jobId = $job->createJob(
'job_type' => 'fetch_feed', $this->Auth->user(),
'job_input' => 'Feed: ' . $feedId, Job::WORKER_DEFAULT,
'status' => 0, 'fetch_feed',
'retries' => 0, 'Feed: ' . $feedId,
'org' => $this->Auth->user('Organisation')['name'], __('Starting fetch from Feed.')
'message' => __('Starting fetch from Feed.'),
); );
$this->Job->save($data);
$jobId = $this->Job->id; $this->Feed->getBackgroundJobsTool()->enqueue(
$process_id = CakeResque::enqueue( BackgroundJobsTool::DEFAULT_QUEUE,
'default', BackgroundJobsTool::CMD_SERVER,
'ServerShell', [
array('fetchFeed', $this->Auth->user('id'), $feedId, $jobId), 'fetchFeed',
true $this->Auth->user('id'),
$feedId,
$jobId
],
true,
$jobId
); );
$this->Job->saveField('process_id', $process_id);
$message = 'Pull queued for background execution.'; $message = 'Pull queued for background execution.';
} else { } else {
$result = $this->Feed->downloadFromFeedInitiator($feedId, $this->Auth->user()); $result = $this->Feed->downloadFromFeedInitiator($feedId, $this->Auth->user());
@ -923,26 +931,30 @@ class FeedsController extends AppController
public function cacheFeeds($scope = 'freetext') public function cacheFeeds($scope = 'freetext')
{ {
if (Configure::read('MISP.background_jobs')) { if (Configure::read('MISP.background_jobs')) {
$this->loadModel('Job');
$this->Job->create(); /** @var Job $job */
$data = array( $job = ClassRegistry::init('Job');
'worker' => 'default', $jobId = $job->createJob(
'job_type' => 'cache_feeds', $this->Auth->user(),
'job_input' => $scope, Job::WORKER_DEFAULT,
'status' => 0, 'cache_feeds',
'retries' => 0, $scope,
'org' => $this->Auth->user('Organisation')['name'], __('Starting feed caching.')
'message' => __('Starting feed caching.'),
); );
$this->Job->save($data);
$jobId = $this->Job->id; $this->Feed->getBackgroundJobsTool()->enqueue(
$process_id = CakeResque::enqueue( BackgroundJobsTool::DEFAULT_QUEUE,
'default', BackgroundJobsTool::CMD_SERVER,
'ServerShell', [
array('cacheFeed', $this->Auth->user('id'), $scope, $jobId), 'cacheFeed',
true $this->Auth->user('id'),
$scope,
$jobId
],
true,
$jobId
); );
$this->Job->saveField('process_id', $process_id);
$message = 'Feed caching job initiated.'; $message = 'Feed caching job initiated.';
} else { } else {
$result = $this->Feed->cacheFeedInitiator($this->Auth->user(), false, $scope); $result = $this->Feed->cacheFeedInitiator($this->Auth->user(), false, $scope);