@@ -28,6 +28,8 @@ sub new ($class, @args) {
2828sub register ($self , $app , @args ) {
2929 $self -> {app } = $app ;
3030 $self -> {config } = $app -> config;
31+ my $config = $self -> {config }-> {amqp };
32+ $config -> {enabled } = 1; # Needed for reloading the plugin later in the forked process
3133 Mojo::IOLoop-> singleton-> next_tick(
3234 sub {
3335 # register for events
@@ -68,18 +70,26 @@ sub publish_amqp ($self, $topic, $event_data, $headers = {}, $remaining_attempts
6870
6971 $remaining_attempts //= $config -> {publish_attempts };
7072 $retry_delay //= $config -> {publish_retry_delay };
71- $publisher -> publish_p($event_data , $headers , routing_key => $topic )-> then(sub { log_debug " $topic published" })
72- -> catch(
73+ $publisher -> publish_p($event_data , $headers , routing_key => $topic )-> then(
74+ sub {
75+ log_debug " $topic published" ;
76+ OpenQA::Events-> singleton-> emit(' amqp_handled' );
77+ }
78+ )-> catch(
7379 sub ($error ) {
7480 my $left = looks_like_number $remaining_attempts && $remaining_attempts > 1 ? $remaining_attempts - 1 : 0;
7581 my $delay = $retry_delay * $config -> {publish_retry_delay_factor };
7682 my ($event_id , $job_id ) = ($event_data -> {id } // ' none' , $event_data -> {job_id });
7783 my $additional_info = $job_id ? " , job ID: $job_id " : ' ' ;
7884 my $log_msg = " Publishing $topic failed: $error (event ID: $event_id$additional_info , $left attempts left)" ;
79- return log_error $log_msg unless $left ;
8085 my $retry_function = sub ($loop ) { $self -> publish_amqp($topic , $event_data , $headers , $left , $delay ) };
81- log_info $log_msg ;
82- Mojo::IOLoop-> timer($retry_delay => $retry_function ) if $left ;
86+ if ($left ) {
87+ log_info $log_msg ;
88+ Mojo::IOLoop-> timer($retry_delay => $retry_function );
89+ return ;
90+ }
91+ OpenQA::Events-> singleton-> emit(' amqp_handled' );
92+ return log_error $log_msg ;
8393 })-> finally(sub { undef $publisher });
8494}
8595
0 commit comments