Skip to content

Commit 8847ecf

Browse files
committed
3961: Commands cleanup
1 parent f062830 commit 8847ecf

File tree

3 files changed

+70
-28
lines changed

3 files changed

+70
-28
lines changed

README.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@ composer require os2web/os2web_audit
2626
drush pm:enable os2web_audit
2727
```
2828

29-
### Drush
29+
## Drush
30+
31+
### Test audit log
3032

3133
The module provides a Drush command named audit:log. This command enables you
3234
to log a test message to the configured logger. The audit:log command accepts a
@@ -39,6 +41,15 @@ and once as an error message.
3941
drush audit:log 'This is a test message'
4042
```
4143

44+
### Retry jobs
45+
46+
The module also comes with method for retrying failed jobs. This will retry,
47+
all failed jobs in the `os2web_audit` queue.
48+
49+
```shell
50+
drush audit:retry-jobs
51+
```
52+
4253
## Usage
4354

4455
The module exposes a simple `Logger` service which can log an `info` and `error`

src/Drush/Commands/Commands.php renamed to src/Drush/Commands/LogMessageCommand.php

Lines changed: 1 addition & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
namespace Drupal\os2web_audit\Drush\Commands;
44

5-
use Drupal\Core\Database\Connection;
6-
use Drupal\advancedqueue\Job;
75
use Drupal\os2web_audit\Service\Logger;
86
use Drush\Attributes\Argument;
97
use Drush\Attributes\Command;
@@ -15,20 +13,17 @@
1513
/**
1614
* Simple command to send log message into audit log.
1715
*/
18-
class Commands extends DrushCommands {
16+
class LogMessageCommand extends DrushCommands {
1917

2018
/**
2119
* Commands constructor.
2220
*
2321
* @param \Drupal\os2web_audit\Service\Logger $auditLogger
2422
* Audit logger service.
25-
* @param \Drupal\Core\Database\Connection $connection
26-
* The database connection.
2723
*/
2824
public function __construct(
2925
#[Autowire(service: 'os2web_audit.logger')]
3026
protected readonly Logger $auditLogger,
31-
protected Connection $connection,
3227
) {
3328
parent::__construct();
3429
}
@@ -39,7 +34,6 @@ public function __construct(
3934
public static function create(ContainerInterface $container): self {
4035
return new static(
4136
$container->get('os2web_audit.logger'),
42-
$container->get('database'),
4337
);
4438
}
4539

@@ -60,24 +54,4 @@ public function logMessage(string $log_message): void {
6054
$this->auditLogger->error('test', $log_message, TRUE, ['from' => 'drush']);
6155
}
6256

63-
/**
64-
* Retries all failed jobs in the os2web_audit queue.
65-
*/
66-
#[Command(name: 'audit:retry-jobs')]
67-
public function retryJobs(): void {
68-
69-
try {
70-
$this->connection->update('advancedqueue')
71-
->fields(['state' => Job::STATE_QUEUED])
72-
->condition('queue_id', 'os2web_audit')
73-
->condition('state', Job::STATE_FAILURE)
74-
->execute();
75-
76-
$this->output()->writeln('Successfully retried all failed jobs.');
77-
}
78-
catch (\Exception $e) {
79-
$this->output()->writeln($e->getMessage());
80-
}
81-
}
82-
8357
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
<?php
2+
3+
namespace Drupal\os2web_audit\Drush\Commands;
4+
5+
use Drupal\Core\Database\Connection;
6+
use Drupal\advancedqueue\Job;
7+
use Drush\Attributes\Command;
8+
use Drush\Commands\DrushCommands;
9+
use Symfony\Component\DependencyInjection\ContainerInterface;
10+
11+
/**
12+
* Simple command to send log message into audit log.
13+
*/
14+
class RetryFailedQueueCommand extends DrushCommands {
15+
16+
/**
17+
* Commands constructor.
18+
*
19+
* @param \Drupal\Core\Database\Connection $connection
20+
* The database connection.
21+
*/
22+
public function __construct(
23+
protected Connection $connection,
24+
) {
25+
parent::__construct();
26+
}
27+
28+
/**
29+
* {@inheritdoc}
30+
*/
31+
public static function create(ContainerInterface $container): self {
32+
return new static(
33+
$container->get('database'),
34+
);
35+
}
36+
37+
/**
38+
* Retries all failed jobs in the os2web_audit queue.
39+
*/
40+
#[Command(name: 'audit:retry-jobs')]
41+
public function retryJobs(): void {
42+
43+
try {
44+
$this->connection->update('advancedqueue')
45+
->fields(['state' => Job::STATE_QUEUED])
46+
->condition('queue_id', 'os2web_audit')
47+
->condition('state', Job::STATE_FAILURE)
48+
->execute();
49+
50+
$this->output()->writeln('Successfully retried all failed jobs.');
51+
}
52+
catch (\Exception $e) {
53+
$this->output()->writeln($e->getMessage());
54+
}
55+
}
56+
57+
}

0 commit comments

Comments
 (0)