chg: refactor server shell background jobs to use new tool

pull/7939/head
Luciano Righetti 2021-10-27 17:03:16 +02:00
parent 5e19ca6761
commit 145b54f401
2 changed files with 49 additions and 15 deletions

View File

@ -1,6 +1,7 @@
<?php
App::uses('Folder', 'Utility');
App::uses('File', 'Utility');
App::uses('BackgroundJobsTool', 'Tools');
require_once 'AppShell.php';
/**
@ -11,8 +12,17 @@ require_once 'AppShell.php';
*/
class ServerShell extends AppShell
{
/** @var BackgroundJobsTool */
private $BackgroundJobsTool;
public $uses = array('Server', 'Task', 'Job', 'User', 'Feed');
public function initialize(): void
{
$this->BackgroundJobsTool = new BackgroundJobsTool();
$this->BackgroundJobsTool->initTool(Configure::read('BackgroundJobs'));
}
public function list()
{
$servers = $this->Server->find('all', [
@ -78,11 +88,18 @@ class ServerShell extends AppShell
));
foreach ($servers as $serverId => $serverName) {
$jobId = CakeResque::enqueue(
'default',
'ServerShell',
array('pull', $user['id'], $serverId, $technique)
$jobId = $this->BackgroundJobsTool->enqueue(
BackgroundJobsTool::DEFAULT_QUEUE,
BackgroundJobsTool::CMD_SERVER,
[
'pull',
$user['id'],
$serverId,
$technique
]
);
$this->out("Enqueued pulling from $serverName server as job $jobId");
}
}
@ -192,11 +209,18 @@ class ServerShell extends AppShell
));
foreach ($servers as $serverId => $serverName) {
$jobId = CakeResque::enqueue(
'default',
'ServerShell',
array('push', $user['id'], $serverId, $technique)
$jobId = $this->BackgroundJobsTool->enqueue(
BackgroundJobsTool::DEFAULT_QUEUE,
BackgroundJobsTool::CMD_SERVER,
[
'push',
$user['id'],
$serverId,
$technique
]
);
$this->out("Enqueued pushing from $serverName server as job $jobId");
}
}
@ -317,11 +341,17 @@ class ServerShell extends AppShell
));
foreach ($servers as $serverId => $serverName) {
$jobId = CakeResque::enqueue(
'default',
'ServerShell',
array('cacheServer', $user['id'], $serverId)
$jobId = $this->BackgroundJobsTool->enqueue(
BackgroundJobsTool::DEFAULT_QUEUE,
BackgroundJobsTool::CMD_SERVER,
[
'cacheServer',
$user['id'],
$serverId
]
);
$this->out("Enqueued cacheServer from {$serverName} server as job $jobId");
}
}

View File

@ -68,14 +68,18 @@ class BackgroundJobsTool
self::UPDATE_QUEUE,
];
public const CMD_EVENT = 'event';
public const
CMD_EVENT = 'event',
CMD_SERVER = 'server';
public const ALLOWED_COMMANDS = [
self::CMD_EVENT
self::CMD_EVENT,
self::CMD_SERVER
];
public const CMD_TO_SHELL_DICT = [
self::CMD_EVENT => 'EventShell'
self::CMD_EVENT => 'EventShell',
self::CMD_SERVER => 'ServerShell'
];
public const JOB_STATUS_PREFIX = 'job_status';