22
33namespace Drupal \os2web_audit \Drush \Commands ;
44
5- use Drush \Attributes \Command ;
5+ use Drupal \Core \Database \Connection ;
6+ use Drupal \advancedqueue \Job ;
67use Drupal \os2web_audit \Service \Logger ;
8+ use Drush \Attributes \Argument ;
9+ use Drush \Attributes \Command ;
710use Drush \Commands \DrushCommands ;
11+ use Drush \Exceptions \CommandFailedException ;
812use Symfony \Component \DependencyInjection \Attribute \Autowire ;
9- use Drush \Attributes \Argument ;
1013use 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