Skip to content

Commit 4757502

Browse files
committed
3961: Added retry jobs command
1 parent db875ed commit 4757502

File tree

2 files changed

+30
-3
lines changed

2 files changed

+30
-3
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
- Added command for retrying jobs.
12+
1113
## [1.0.1] - 2025-03-06
1214

1315
- Handled webform elements not present in submission data

src/Drush/Commands/Commands.php

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
namespace Drupal\os2web_audit\Drush\Commands;
44

5-
use Drush\Attributes\Command;
5+
use Drupal\Core\Database\Connection;
6+
use Drupal\advancedqueue\Job;
67
use Drupal\os2web_audit\Service\Logger;
8+
use Drush\Attributes\Argument;
9+
use Drush\Attributes\Command;
710
use Drush\Commands\DrushCommands;
11+
use Drush\Exceptions\CommandFailedException;
812
use Symfony\Component\DependencyInjection\Attribute\Autowire;
9-
use Drush\Attributes\Argument;
1013
use Symfony\Component\DependencyInjection\ContainerInterface;
11-
use Drush\Exceptions\CommandFailedException;
1214

1315
/**
1416
* Simple command to send log message into audit log.
@@ -24,6 +26,7 @@ class Commands extends DrushCommands {
2426
public function __construct(
2527
#[Autowire(service: 'os2web_audit.logger')]
2628
protected readonly Logger $auditLogger,
29+
protected Connection $connection,
2730
) {
2831
parent::__construct();
2932
}
@@ -34,6 +37,7 @@ public function __construct(
3437
public static function create(ContainerInterface $container): self {
3538
return new static(
3639
$container->get('os2web_audit.logger'),
40+
$container->get('database'),
3741
);
3842
}
3943

@@ -54,4 +58,25 @@ public function logMessage(string $log_message): void {
5458
$this->auditLogger->error('test', $log_message, TRUE, ['from' => 'drush']);
5559
}
5660

61+
/**
62+
* Retries all failed jobs in the os2web_audit queue.
63+
*/
64+
#[Command(name: 'audit:retry-jobs')]
65+
public function retryJobs(): void {
66+
67+
try {
68+
$this->connection->update('advancedqueue')
69+
->fields(['state' => Job::STATE_QUEUED])
70+
->condition('queue_id', 'os2web_audit')
71+
->condition('state', Job::STATE_FAILURE)
72+
->execute();
73+
}
74+
catch (\Exception $e) {
75+
$this->io()->error($e->getMessage());
76+
}
77+
78+
$this->io()->success('Successfully retried all failed jobs.');
79+
80+
}
81+
5782
}

0 commit comments

Comments
 (0)