fix: [workers] Worker name when processing freetext

pull/7190/head
Jakub Onderka 2021-03-10 21:33:10 +01:00
parent 2f1efc4561
commit 032302dbf9
5 changed files with 57 additions and 72 deletions

View File

@ -5712,14 +5712,14 @@ class EventsController extends AppController
$job = ClassRegistry::init('Job');
$job->create();
$data = array(
'worker' => $this->Event->__getPrioWorkerIfPossible(),
'job_type' => $job_type,
'job_input' => sprintf('Event ID: %s', $id),
'status' => 0,
'retries' => 0,
'org_id' => 0,
'org' => 'ADMIN',
'message' => $message
'worker' => 'prio',
'job_type' => $job_type,
'job_input' => sprintf('Event ID: %s', $id),
'status' => 0,
'retries' => 0,
'org_id' => 0,
'org' => 'ADMIN',
'message' => $message
);
$job->save($data);
$jobId = $job->id;

View File

@ -4467,19 +4467,6 @@ class Event extends AppModel
}
}
public function __getPrioWorkerIfPossible()
{
$this->ResqueStatus = new ResqueStatus\ResqueStatus(Resque::redis());
$workers = $this->ResqueStatus->getWorkers();
$workerType = 'default';
foreach ($workers as $worker) {
if ($worker['queue'] === 'prio') {
$workerType = 'prio';
}
}
return $workerType;
}
public function publishRouter($id, $passAlong = null, $user, $scope = 'events')
{
if (Configure::read('MISP.background_jobs')) {
@ -4493,14 +4480,14 @@ class Event extends AppModel
$job = ClassRegistry::init('Job');
$job->create();
$data = array(
'worker' => $this->__getPrioWorkerIfPossible(),
'job_type' => 'publish_event',
'job_input' => 'Event ID: ' . $id,
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => $message
'worker' => 'prio',
'job_type' => 'publish_event',
'job_input' => 'Event ID: ' . $id,
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => $message
);
$job->save($data);
$jobId = $job->id;
@ -5914,14 +5901,14 @@ class Event extends AppModel
$job = ClassRegistry::init('Job');
$job->create();
$data = array(
'worker' => $this->__getPrioWorkerIfPossible(),
'job_type' => 'enrichment',
'job_input' => 'Event ID: ' . $options['event_id'] . ' modules: ' . json_encode($options['modules']),
'status' => 0,
'retries' => 0,
'org_id' => $options['user']['org_id'],
'org' => $options['user']['Organisation']['name'],
'message' => 'Enriching event.',
'worker' => 'prio',
'job_type' => 'enrichment',
'job_input' => 'Event ID: ' . $options['event_id'] . ' modules: ' . json_encode($options['modules']),
'status' => 0,
'retries' => 0,
'org_id' => $options['user']['org_id'],
'org' => $options['user']['Organisation']['name'],
'message' => 'Enriching event.',
);
$job->save($data);
$jobId = $job->id;
@ -6685,19 +6672,19 @@ class Event extends AppModel
return $this->processModuleResultsData($user, $resolved_data, $id, $default_comment = '');
}
private function __initiateProcessJob($user, $id, $format = 'freetext')
private function __initiateProcessJob(array $user, $id, $format = 'freetext')
{
$job = ClassRegistry::init('Job');
$job->create();
$data = array(
'worker' => 'default',
'job_type' => __('process_' . $format . '_data'),
'job_input' => 'Event: ' . $id,
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => 'Processing...'
'worker' => 'prio',
'job_type' => 'process_' . $format . '_data',
'job_input' => 'Event: ' . $id,
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => 'Processing...'
);
$job->save($data);
$randomFileName = $this->generateRandomFileName() . '.json';

View File

@ -459,14 +459,14 @@ class GalaxyCluster extends AppModel
$job = ClassRegistry::init('Job');
$job->create();
$data = array(
'worker' => $this->Event->__getPrioWorkerIfPossible(),
'job_type' => 'publish_galaxy_clusters',
'job_input' => 'Cluster ID: ' . $clusterId,
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => $message
'worker' => 'prio',
'job_type' => 'publish_galaxy_clusters',
'job_input' => 'Cluster ID: ' . $clusterId,
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => $message
);
$job->save($data);
$jobId = $job->id;

View File

@ -3924,16 +3924,15 @@ class Server extends AppModel
if (Configure::read('MISP.background_jobs')) {
$job = ClassRegistry::init('Job');
$job->create();
$eventModel = ClassRegistry::init('Event');
$data = array(
'worker' => $eventModel->__getPrioWorkerIfPossible(),
'job_type' => __('update_after_pull'),
'job_input' => __('Updating: ' . $submodule_name),
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => 'Update the database after PULLing the submodule(s).',
'worker' => 'prio',
'job_type' => __('update_after_pull'),
'job_input' => __('Updating: ' . $submodule_name),
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => 'Update the database after PULLing the submodule(s).',
);
$job->save($data);
$jobId = $job->id;

View File

@ -1028,16 +1028,15 @@ class User extends AppModel
if (Configure::read('MISP.background_jobs')) {
$job = ClassRegistry::init('Job');
$job->create();
$eventModel = ClassRegistry::init('Event');
$data = array(
'worker' => $eventModel->__getPrioWorkerIfPossible(),
'job_type' => __('reset_all_sync_api_keys'),
'job_input' => __('Reseting all API keys'),
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => 'Issuing new API keys to all sync users.',
'worker' => 'prio',
'job_type' => __('reset_all_sync_api_keys'),
'job_input' => __('Reseting all API keys'),
'status' => 0,
'retries' => 0,
'org_id' => $user['org_id'],
'org' => $user['Organisation']['name'],
'message' => 'Issuing new API keys to all sync users.',
);
$job->save($data);
$jobId = $job->id;