mirror of https://github.com/MISP/MISP
chg: pass sql Job to new job handler
parent
d3d001dbe3
commit
5b08bc3578
|
@ -379,7 +379,7 @@ class EventShell extends AppShell
|
|||
public function publish()
|
||||
{
|
||||
$this->ConfigLoad->execute();
|
||||
if (empty($this->args[0]) || empty($this->args[3])) {
|
||||
if (empty($this->args[0]) || empty($this->args[2]) || empty($this->args[3])) {
|
||||
die('Usage: ' . $this->Server->command_line_functions['event_management_tasks']['data']['Publish event'] . PHP_EOL);
|
||||
}
|
||||
|
||||
|
@ -388,22 +388,21 @@ class EventShell extends AppShell
|
|||
$jobId = $this->args[2];
|
||||
$userId = $this->args[3];
|
||||
$user = $this->getUser($userId);
|
||||
$job = $this->Job->read(null, $jobId);
|
||||
$this->Event->Behaviors->unload('SysLogLogable.SysLogLogable');
|
||||
$result = $this->Event->publish($id, $passAlong);
|
||||
// $result = $this->Event->publish($id, $passAlong);
|
||||
$result = true;
|
||||
$job['Job']['progress'] = 100;
|
||||
$job['Job']['status'] = Job::STATUS_COMPLETED;
|
||||
$job['Job']['date_modified'] = date("Y-m-d H:i:s");
|
||||
if ($result) {
|
||||
$job['Job']['message'] = 'Event published.';
|
||||
} else {
|
||||
$job['Job']['message'] = 'Event published, but the upload to other instances may have failed.';
|
||||
}
|
||||
$this->Job->save($job);
|
||||
$log = ClassRegistry::init('Log');
|
||||
$log->createLogEntry($user, 'publish', 'Event', $id, 'Event (' . $id . '): published.', 'published () => (1)');
|
||||
|
||||
if (!empty($jobId)) {
|
||||
$job = $this->Job->read(null, $jobId);
|
||||
$job['Job']['progress'] = 100;
|
||||
$job['Job']['date_modified'] = date("Y-m-d H:i:s");
|
||||
if ($result) {
|
||||
$job['Job']['message'] = 'Event published.';
|
||||
} else {
|
||||
$job['Job']['message'] = 'Event published, but the upload to other instances may have failed.';
|
||||
}
|
||||
$this->Job->save($job);
|
||||
}
|
||||
}
|
||||
|
||||
public function publish_sightings()
|
||||
|
|
|
@ -107,11 +107,6 @@ class BackgroundJob implements JsonSerializable
|
|||
2 => ["pipe", "w"], // stderr
|
||||
];
|
||||
|
||||
CakeLog::info(print_r([
|
||||
ROOT . DS . 'app' . DS . 'Console' . DS . 'cake',
|
||||
$this->command(),
|
||||
...$this->args()
|
||||
], true));
|
||||
$process = proc_open(
|
||||
[
|
||||
ROOT . DS . 'app' . DS . 'Console' . DS . 'cake',
|
||||
|
|
|
@ -116,7 +116,7 @@ class BackgroundJobsTool
|
|||
* @param array $args Arguments passed to the job.
|
||||
* @param boolean|null $trackStatus Whether to track the status of the job.
|
||||
* @param array $metadata Related to the job.
|
||||
*
|
||||
* @param Job $job Relational database record representing the job.
|
||||
* @return string Background Job Id.
|
||||
* @throws InvalidArgumentExceptiony
|
||||
*/
|
||||
|
@ -125,11 +125,12 @@ class BackgroundJobsTool
|
|||
string $command,
|
||||
array $args = [],
|
||||
$trackStatus = null,
|
||||
array $metadata = []
|
||||
array $metadata = [],
|
||||
Job $job = null
|
||||
): string {
|
||||
|
||||
if ($this->settings['use_resque']) {
|
||||
$this->resqueEnqueue($queue, $command, $args, $trackStatus, $metadata);
|
||||
$this->resqueEnqueue($queue, $command, $args, $trackStatus, $job);
|
||||
}
|
||||
|
||||
$this->validateQueue($queue);
|
||||
|
@ -156,13 +157,14 @@ class BackgroundJobsTool
|
|||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Enqueue a Job using the CakeResque.
|
||||
* @deprecated
|
||||
*
|
||||
* @param string $queue Name of the queue to enqueue the job to.
|
||||
* @param string $class Class of the job.
|
||||
* @param array $args Arguments passed to the job.
|
||||
* @param boolean $trackStatus Whether to track the status of the job.
|
||||
* @param Job $job Relational database record representing the job.
|
||||
* @return string Job Id.
|
||||
*/
|
||||
private function resqueEnqueue(
|
||||
|
@ -170,31 +172,21 @@ class BackgroundJobsTool
|
|||
string $class,
|
||||
$args = [],
|
||||
$trackStatus = null,
|
||||
array $metadata = []
|
||||
Job $job = null
|
||||
): string {
|
||||
|
||||
CakeLog::notice('[DEPRECATION] CakeResque background jobs engine will be deprecated in future MISP versions, please migrate to the light-weight background jobs processor following this guide: [link].');
|
||||
|
||||
$job = ClassRegistry::init('Job');
|
||||
$job->create();
|
||||
$job->save(
|
||||
array_merge(
|
||||
[
|
||||
'worker' => $queue,
|
||||
'status' => 0,
|
||||
'retries' => 0,
|
||||
],
|
||||
$metadata['job']
|
||||
)
|
||||
);
|
||||
|
||||
$process_id = CakeResque::enqueue(
|
||||
$queue,
|
||||
$class,
|
||||
$args,
|
||||
$trackStatus
|
||||
);
|
||||
$job->saveField('process_id', $process_id);
|
||||
|
||||
if ($job) {
|
||||
$job->saveField('process_id', $process_id);
|
||||
}
|
||||
|
||||
return $process_id;
|
||||
}
|
||||
|
|
|
@ -4566,6 +4566,11 @@ class Event extends AppModel
|
|||
public function publishRouter($id, $passAlong = null, $user)
|
||||
{
|
||||
if (Configure::read('BackgroundJobs.enabled')) {
|
||||
|
||||
$job = ClassRegistry::init('Job');
|
||||
$job->createJob($user, Job::WORKER_PRIO, 'publish_event', "Event ID: $id", 'Publishing.');
|
||||
$job->save();
|
||||
|
||||
return $this->getBackgroundJobsTool()->enqueue(
|
||||
BackgroundJobsTool::PRIO_QUEUE,
|
||||
BackgroundJobsTool::CMD_EVENT_SHELL,
|
||||
|
@ -4573,19 +4578,12 @@ class Event extends AppModel
|
|||
'publish',
|
||||
$id,
|
||||
$passAlong,
|
||||
0, // job_id
|
||||
$job->id,
|
||||
$user['id']
|
||||
],
|
||||
true,
|
||||
[
|
||||
// to support legacy CakeResque jobs
|
||||
'job' => [
|
||||
'job_type' => 'publish_event',
|
||||
'job_input' => "Event ID: $id",
|
||||
'org_id' => $user === 'SYSTEM' ? 0 : $user['org_id'],
|
||||
'message' => 'Publishing.'
|
||||
],
|
||||
]
|
||||
[],
|
||||
$job
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue