PHRAS-4057: log_doc - report mark as "cancel" for running_job entry (#4501)

* log_docs mark as canceled too

* PHRAS-4058 auto cancelling job

* add auto-cancelingJob in hour in the config

* add patch rc12
This commit is contained in:
Aina Sitraka
2024-04-30 12:44:14 +03:00
committed by GitHub
parent 7e3fe51a2c
commit b0eba5217c
8 changed files with 157 additions and 5 deletions

View File

@@ -2,24 +2,38 @@
namespace Alchemy\Phrasea\WorkerManager\Worker;
use Alchemy\Phrasea\Application\Helper\ApplicationBoxAware;
use Alchemy\Phrasea\Application\Helper\DataboxLoggerAware;
use Alchemy\Phrasea\Core\Configuration\PropertyAccess;
use Alchemy\Phrasea\Model\Entities\WorkerJob;
use Alchemy\Phrasea\Model\Entities\WorkerRunningJob;
use Alchemy\Phrasea\Model\Repositories\WorkerJobRepository;
use Alchemy\Phrasea\Model\Repositories\WorkerRunningJobRepository;
use Alchemy\Phrasea\WorkerManager\Event\RecordEditInWorkerEvent;
use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
class MainQueueWorker implements WorkerInterface
{
use ApplicationBoxAware;
use DataboxLoggerAware;
private $messagePublisher;
private $repoWorkerJob;
private $repoWorkerRunningJob;
private $conf;
public function __construct(
MessagePublisher $messagePublisher,
WorkerJobRepository $repoWorkerJob
WorkerJobRepository $repoWorkerJob,
WorkerRunningJobRepository $repoWorkerRunningJob,
PropertyAccess $conf
)
{
$this->messagePublisher = $messagePublisher;
$this->repoWorkerJob = $repoWorkerJob;
$this->repoWorkerRunningJob = $repoWorkerRunningJob;
$this->conf = $conf;
}
public function process(array $payload)
@@ -29,6 +43,31 @@ class MainQueueWorker implements WorkerInterface
'payload' => $payload
];
$autoCancelingJob = $this->conf->get(['workers', 'auto-cancelingJob'], null);
if (!empty($autoCancelingJob)) {
$autoCancelingJob = intval($autoCancelingJob);
// first get the workerRunningJobs for log_docs 'subdefCreation', 'writeMetadatas'
$workerRunningJobs = $this->repoWorkerRunningJob->getRunningSinceCreated($autoCancelingJob, ['subdefCreation', 'writeMetadatas']);
// update the status for table workerRunningJob
$this->repoWorkerRunningJob->updateStatusRunningToCanceledSinceCreated($autoCancelingJob);
// last, treat the log_docs
$finishedDate = new \DateTime('now');
/** @var WorkerRunningJob $workerRunningJob */
foreach ($workerRunningJobs as $workerRunningJob) {
$databox = $this->findDataboxById($workerRunningJob->getDataboxId());
$record = $databox->get_record($workerRunningJob->getRecordId());
$subdefName = $workerRunningJob->getWorkOn();
$action = $workerRunningJob->getWork();
$status = 'canceled';
$this->getDataboxLogger($databox)->initOrUpdateLogDocsFromWorker($record, $databox, $workerRunningJob, $subdefName, $action, $finishedDate, $status);
}
}
$em = $this->repoWorkerJob->getEntityManager();
$em->getConnection()->beginTransaction();
/** @var WorkerJob $workerJob */