mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-18 15:33:15 +00:00
PHRAS-3525 Admin can change status to canceled for multiple job (#4055)
- Can change status to canceled for multiple running jobs - Add confirm when clear table - Workers, adding try catch on recordadapter for - Delete Worker - Webhook Worker - Subdefinition Worker
This commit is contained in:
@@ -7,6 +7,7 @@ use Alchemy\Phrasea\WorkerManager\Queue\MessagePublisher;
|
||||
use DateTime;
|
||||
use Doctrine\DBAL\Driver\Connection;
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Doctrine\ORM\Query\ResultSetMappingBuilder;
|
||||
use Exception;
|
||||
use PDO;
|
||||
|
||||
@@ -391,6 +392,44 @@ class WorkerRunningJobRepository extends EntityRepository
|
||||
return $qb->getQuery()->getResult();
|
||||
}
|
||||
|
||||
public function updateStatusRunningToCanceledSinceCreated($hour = 0)
|
||||
{
|
||||
$sql = '
|
||||
UPDATE WorkerRunningJob w
|
||||
SET w.status = :canceled
|
||||
WHERE w.status = :running
|
||||
AND (TO_SECONDS(CURRENT_TIMESTAMP()) - TO_SECONDS(w.created)) > :second'
|
||||
;
|
||||
|
||||
$this->_em->getConnection()->executeUpdate($sql, [
|
||||
'second' => $hour * 3600,
|
||||
'running' => 'running',
|
||||
'canceled' => 'canceled'
|
||||
]);
|
||||
}
|
||||
|
||||
public function getRunningSinceCreated($hour = 0)
|
||||
{
|
||||
$rsm = new ResultSetMappingBuilder($this->_em);
|
||||
$rsm->addRootEntityFromClassMetadata('Alchemy\Phrasea\Model\Entities\WorkerRunningJob', 'w');
|
||||
$selectClause = $rsm->generateSelectClause();
|
||||
|
||||
$sql = '
|
||||
SELECT ' . $selectClause . '
|
||||
FROM WorkerRunningJob w
|
||||
WHERE w.status = :running
|
||||
AND (TO_SECONDS(CURRENT_TIMESTAMP()) - TO_SECONDS(w.created)) > :second'
|
||||
;
|
||||
|
||||
$q = $this->_em->createNativeQuery($sql, $rsm);
|
||||
$q->setParameters([
|
||||
'second' => $hour * 3600,
|
||||
'running' => 'running'
|
||||
]);
|
||||
|
||||
return $q->getResult();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $commitId
|
||||
* @return bool
|
||||
|
@@ -174,6 +174,38 @@ class AdminConfigurationController extends Controller
|
||||
return $this->app->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function changeStatusCanceledAction(PhraseaApplication $app, Request $request)
|
||||
{
|
||||
/** @var WorkerRunningJobRepository $repoWorker */
|
||||
$repoWorker = $this->app['repo.worker-running-job'];
|
||||
|
||||
$result = $repoWorker->getRunningSinceCreated($request->get('hour'));
|
||||
return $this->render('admin/worker-manager/worker_info_change_status.html.twig', [
|
||||
'jobCount' => count($result)
|
||||
]);
|
||||
}
|
||||
|
||||
public function doChangeStatusToCanceledAction(PhraseaApplication $app, Request $request)
|
||||
{
|
||||
/** @var WorkerRunningJobRepository $repoWorker */
|
||||
$repoWorker = $this->app['repo.worker-running-job'];
|
||||
$repoWorker->updateStatusRunningToCanceledSinceCreated($request->request->get('hour'));
|
||||
|
||||
return $this->app->json(['success' => true]);
|
||||
}
|
||||
|
||||
public function getRunningAction(PhraseaApplication $app, Request $request)
|
||||
{
|
||||
/** @var WorkerRunningJobRepository $repoWorker */
|
||||
$repoWorker = $this->app['repo.worker-running-job'];
|
||||
$result = $repoWorker->getRunningSinceCreated($request->get('hour'));
|
||||
|
||||
return $this->app->json([
|
||||
'success' => true,
|
||||
'count' => count($result)
|
||||
]);
|
||||
}
|
||||
|
||||
public function queueMonitorAction(PhraseaApplication $app, Request $request)
|
||||
{
|
||||
$reload = ($request->query->get('reload') == 1);
|
||||
|
@@ -135,6 +135,21 @@ class ControllerServiceProvider implements ControllerProviderInterface, ServiceP
|
||||
->assert('workerId', '\d+')
|
||||
->bind('worker_admin_change_status');
|
||||
|
||||
/** @uses AdminConfigurationController::changeStatusCanceledAction */
|
||||
$controllers->match('/change-status/canceled', 'controller.worker.admin.configuration:changeStatusCanceledAction')
|
||||
->method('GET')
|
||||
->bind('worker_admin_change_status_canceled');
|
||||
|
||||
/** @uses AdminConfigurationController::doChangeStatusToCanceledAction */
|
||||
$controllers->match('/change-status/canceled', 'controller.worker.admin.configuration:doChangeStatusToCanceledAction')
|
||||
->method('POST')
|
||||
->bind('worker_admin_do_change_status_canceled');
|
||||
|
||||
/** @uses AdminConfigurationController::getRunningAction */
|
||||
$controllers->match('/running', 'controller.worker.admin.configuration:getRunningAction')
|
||||
->method('GET')
|
||||
->bind('worker_admin_get_running');
|
||||
|
||||
return $controllers;
|
||||
}
|
||||
|
||||
|
@@ -52,13 +52,21 @@ class DeleteRecordWorker implements WorkerInterface
|
||||
$em->rollback();
|
||||
}
|
||||
|
||||
try {
|
||||
$databox = $this->findDataboxById($payload['databoxId']);
|
||||
$record = $databox->get_record($payload['recordId']);
|
||||
|
||||
$databox = $this->findDataboxById($payload['databoxId']);
|
||||
$record = $databox->get_record($payload['recordId']);
|
||||
$record->delete();
|
||||
|
||||
$record->delete();
|
||||
$this->messagePublisher->pushLog(sprintf("record deleted databoxname=%s databoxid=%d recordid=%d", $databox->get_viewname(), $payload['databoxId'], $payload['recordId']));
|
||||
} catch (\Exception $e) {
|
||||
$this->messagePublisher->pushLog(sprintf("%s (%s) : Error %s", __FILE__, __LINE__, $e->getMessage()), 'error');
|
||||
if ($workerRunningJob != null) {
|
||||
$workerRunningJob->setInfo('error : ' . $e->getMessage());
|
||||
$em->persist($workerRunningJob);
|
||||
}
|
||||
}
|
||||
|
||||
$this->messagePublisher->pushLog(sprintf("record deleted databoxname=%s databoxid=%d recordid=%d", $databox->get_viewname(), $payload['databoxId'], $payload['recordId']));
|
||||
// tell that the delete is finished
|
||||
if ($workerRunningJob != null) {
|
||||
$workerRunningJob
|
||||
|
@@ -65,8 +65,14 @@ class SubdefCreationWorker implements WorkerInterface
|
||||
$databoxId = $payload['databoxId'];
|
||||
$subdefName = $payload['subdefName'];
|
||||
|
||||
$databox = $this->findDataboxById($databoxId);
|
||||
$record = $databox->get_record($recordId);
|
||||
try {
|
||||
$databox = $this->findDataboxById($databoxId);
|
||||
$record = $databox->get_record($recordId);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error(sprintf("%s (%s) : record not found %s", __FILE__, __LINE__, $e->getMessage()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($record->isStory()) {
|
||||
return;
|
||||
|
@@ -114,7 +114,15 @@ class WebhookWorker implements WorkerInterface
|
||||
|
||||
$this->messagePublisher->pushLog(sprintf('Processing event "%s" with id %d', $webhookevent->getName(), $webhookevent->getId()));
|
||||
// send requests
|
||||
$this->deliverEvent($httpClient, $thirdPartyApplications, $webhookevent, $payload);
|
||||
try {
|
||||
$this->deliverEvent($httpClient, $thirdPartyApplications, $webhookevent, $payload);
|
||||
} catch (\Exception $e) {
|
||||
if ($workerRunningJob != null) {
|
||||
$workerRunningJob->setInfo('error ' . $e->getMessage());
|
||||
$em->persist($workerRunningJob);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ($workerRunningJob != null) {
|
||||
|
@@ -89,7 +89,13 @@ class WriteMetadatasWorker implements WorkerInterface
|
||||
|
||||
// here we can work
|
||||
|
||||
$record = $databox->get_record($recordId);
|
||||
try {
|
||||
$record = $databox->get_record($recordId);
|
||||
} catch (\Exception $e) {
|
||||
$this->repoWorker->markFinished($workerRunningJobId, "error " . $e->getMessage());
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if ($record->getMimeType() == 'image/svg+xml') {
|
||||
|
||||
|
Reference in New Issue
Block a user