Skip to content

Commit cd11eba

Browse files
committed
fix: issue with job pause management
1 parent 4cfc1bf commit cd11eba

File tree

12 files changed

+62
-16
lines changed

12 files changed

+62
-16
lines changed

src/bundle/Controller/Admin/JobController.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,15 @@ public function run(Job $job, int $batchLimit = null, bool $reset = false): Resp
188188
]));
189189
}
190190

191+
public function pause(Job $job): Response
192+
{
193+
$this->jobService->pause($job);
194+
195+
return new RedirectResponse($this->generateUrl('import_export.job.view', [
196+
'id' => $job->getId(),
197+
]));
198+
}
199+
191200
public function cancel(Job $job): Response
192201
{
193202
$this->jobService->cancelJob($job);

src/bundle/Resources/config/routes.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ import_export.job.run:
1515
path: /import-export/job/{id}/run
1616
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::run }
1717

18+
import_export.job.pause:
19+
path: /import-export/job/{id}/pause
20+
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::pause }
21+
1822
import_export.job.cancel:
1923
path: /import-export/job/{id}/cancel
2024
defaults: { _controller: AlmaviaCX\Bundle\IbexaImportExportBundle\Controller\Admin\JobController::cancel }

src/bundle/Resources/translations/import_export.en.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ job.run: Run
1717
job.status.canceled: Canceled
1818
job.status.completed: Completed
1919
job.status.paused: Paused
20+
job.status.force_paused: Paused
2021
job.status.pending: Pending
2122
job.status.queued: Queued
2223
job.status.running: Running

src/bundle/Resources/translations/import_export.fr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ job.run: Lancer
1717
job.status.canceled: Annulé
1818
job.status.completed: Complété
1919
job.status.paused: 'En pause'
20+
job.status.force_paused: 'En pause'
2021
job.status.pending: 'En attente'
2122
job.status.queued: 'Dans la file'
2223
job.status.running: 'En cours'

src/bundle/Resources/views/themes/admin/import_export/job/list.html.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@
5252
'job.status.completed'|trans()|desc('Completed'),
5353
'job.status.queued'|trans()|desc('Queued'),
5454
'job.status.paused'|trans()|desc('Paused'),
55-
'job.status.canceled'|trans()|desc('Canceled')
56-
55+
'job.status.canceled'|trans()|desc('Canceled'),
56+
'job.status.force_paused'|trans()|desc('Paused')
5757
] %}
5858
{% set show_table_notice = false %}
5959

src/bundle/Resources/views/themes/admin/import_export/job/view.html.twig

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@
3232
'job.status.completed'|trans()|desc('Completed'),
3333
'job.status.queued'|trans()|desc('Queued'),
3434
'job.status.paused'|trans()|desc('Paused'),
35-
'job.status.canceled'|trans()|desc('Canceled')
36-
35+
'job.status.canceled'|trans()|desc('Canceled'),
36+
'job.status.force_paused'|trans()|desc('Paused')
3737
] %}
3838
{% set progress_bar %}</div>
3939
{% include '@ibexadesign/import_export/components/progress_bar.html.twig' with {processedCount: job.processedItemsCount, totalCount: job.totalItemsCount} only %}
@@ -82,7 +82,18 @@
8282
{{ 'job.cancel'|trans|desc('Cancel') }}
8383
</span>
8484
</a>
85-
{% endif %}
85+
<a
86+
href="{{ path('import_export.job.pause', {'id': job.id}) }}"
87+
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
88+
>
89+
<svg class="ibexa-icon ibexa-icon--small ibexa-icon--edit">
90+
<use xlink:href="{{ ibexa_icon_path('interface-block') }}"></use>
91+
</svg>
92+
<span class="ibexa-btn__label">
93+
{{ 'job.pause'|trans|desc('pause') }}
94+
</span>
95+
</a>
96+
{% else %}
8697
<a
8798
href="{{ path('import_export.job.run', {'id': job.id}) }}"
8899
class="btn ibexa-btn ibexa-btn--ghost ibexa-btn--small"
@@ -94,6 +105,7 @@
94105
{{ 'job.run'|trans|desc('Run') }}
95106
</span>
96107
</a>
108+
{% endif %}
97109
{% endset %}
98110

99111
<section class="container ibexa-container">

src/lib/AdminUi/Menu/Event/MenuListener.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Ibexa\AdminUi\Menu\Event\ConfigureMenuEvent;
88
use Ibexa\AdminUi\Menu\MainMenuBuilder;
99
use Ibexa\Contracts\Core\Repository\PermissionResolver;
10-
use Ibexa\Core\Base\Exceptions\UnauthorizedException;
1110
use JMS\TranslationBundle\Model\Message;
1211
use JMS\TranslationBundle\Translation\TranslationContainerInterface;
1312
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

src/lib/Job/AbstractJobRunner.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ public function __invoke(Job $job, int $batchLimit = -1, bool $reset = false): i
2323
$job->reset();
2424
}
2525

26-
if (Job::STATUS_PAUSED !== $job->getStatus() || Job::STATUS_PENDING !== $job->getStatus()) {
27-
return $this->run($job, $batchLimit);
26+
if (!$job->isPending()) {
27+
return $job->getStatus();
2828
}
2929

30-
return $job->getStatus();
30+
return $this->run($job, $batchLimit);
3131
}
3232

3333
abstract protected function run(Job $job, int $batchLimit = -1): int;

src/lib/Job/AsyncJobRunner.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ public function __construct(
2424

2525
protected function run(Job $job, int $batchLimit = -1): int
2626
{
27-
$job->setStatus(Job::STATUS_QUEUED);
28-
$this->jobRepository->save($job);
29-
30-
$this->jobRunMessageHandler->triggerStart($job, $batchLimit);
27+
if ($job->isPaused()) {
28+
$this->jobRunMessageHandler->triggerResume($job, $batchLimit);
29+
} else {
30+
$job->setStatus(Job::STATUS_QUEUED);
31+
$this->jobRepository->save($job);
32+
$this->jobRunMessageHandler->triggerStart($job, $batchLimit);
33+
}
3134

3235
return $job->getStatus();
3336
}

src/lib/Job/Job.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class Job
2424
public const STATUS_COMPLETED = 2;
2525
public const STATUS_QUEUED = 3;
2626
public const STATUS_PAUSED = 4;
27+
public const STATUS_FORCE_PAUSED = 6;
2728
public const STATUS_CANCELED = 5;
2829

2930
/**
@@ -306,4 +307,14 @@ public function isRunning(): bool
306307
{
307308
return self::STATUS_RUNNING === $this->status;
308309
}
310+
311+
public function isPaused(): bool
312+
{
313+
return in_array($this->status, [self::STATUS_PAUSED, self::STATUS_FORCE_PAUSED]);
314+
}
315+
316+
public function isPending(): bool
317+
{
318+
return self::STATUS_PENDING === $this->status || $this->isPaused();
319+
}
309320
}

0 commit comments

Comments
 (0)