Hook up the retryable tasks with hydra-notify

This commit is contained in:
Graham Christensen 2021-08-26 21:53:51 -04:00
parent c0e86faa78
commit ea3ae0693e
3 changed files with 11 additions and 2 deletions

View file

@ -6,6 +6,7 @@ use utf8;
use base 'DBIx::Class::ResultSet'; use base 'DBIx::Class::ResultSet';
use List::Util qw(max); use List::Util qw(max);
use Hydra::Math qw(exponential_backoff); use Hydra::Math qw(exponential_backoff);
use Hydra::Task;
=head2 get_seconds_to_next_retry =head2 get_seconds_to_next_retry

View file

@ -254,7 +254,7 @@ sub failure {
my $event_labels = $self->prom_labels_for_task($task); my $event_labels = $self->prom_labels_for_task($task);
if (defined($task->{"record"})) { if (defined($task->{"record"})) {
if ($task->{"record"}->{"attempts"} > 100) { if ($task->{"record"}->attempts > 100) {
$self->{"prometheus"}->inc("notify_plugin_drop", $event_labels); $self->{"prometheus"}->inc("notify_plugin_drop", $event_labels);
$task->{"record"}->delete(); $task->{"record"}->delete();
} else { } else {

View file

@ -101,10 +101,12 @@ for my $build ($db->resultset('Builds')->search(
$task_dispatcher->dispatch_event($event); $task_dispatcher->dispatch_event($event);
} }
my $taskretries = $db->resultset('TaskRetries');
# Process incoming notifications. # Process incoming notifications.
while (!$queued_only) { while (!$queued_only) {
$prom->inc("event_loop_iterations"); $prom->inc("event_loop_iterations");
my $messages = $listener->block_for_messages(); my $messages = $listener->block_for_messages($taskretries->get_seconds_to_next_retry());
while (my $message = $messages->()) { while (my $message = $messages->()) {
$prom->set("event_received", time()); $prom->set("event_received", time());
my $channelName = $message->{"channel"}; my $channelName = $message->{"channel"};
@ -128,4 +130,10 @@ while (!$queued_only) {
print STDERR "error processing message '$payload' on channel '$channelName': $@\n"; print STDERR "error processing message '$payload' on channel '$channelName': $@\n";
} }
} }
my $task = $taskretries->getRetryableTask();
if (defined($task)) {
$task_dispatcher->dispatchTask($task);
}
} }