ResultSet::TaskRetries: add missing method, get_retryable_task

[?]
Sep 7, 2021, 2:56 PM
JJ2QQV6YNIOKCL44RCCFDUD2J3LJ5FDYJQSZUOACPP44SNS7P2YQC

Dependencies

  • [2] DHOKYWTS Hook up the retryable tasks with hydra-notify
  • [3] 32KJOERM Turn hydra-notify into a daemon
  • [4] IBXWOZCL ResultSet::TaskRetries: teach about saving tasks
  • [5] GMOI3OFS ResultSet::TaskRetries: add get_seconds_to_next_retry
  • [6] IE2PRAQU hydra-queue-runner: Send build notifications

Change contents

  • edit in src/lib/Hydra/Schema/ResultSet/TaskRetries.pm at line 69
    [3.555]
    [3.555]
    }
    =head2 get_retryable_task
    =cut
    sub get_retryable_task {
    my ($self) = @_;
    my $row = $self->get_retryable_taskretries_row();
    if (!defined($row)) {
    return undef;
    }
    my $event = Hydra::Event->new_event(
    $row->get_column("channel"),
    $row->get_column("payload")
    );
    my $task = Hydra::Task->new($event, $row->get_column("pluginname"));
    $task->{"record"} = $row;
    return $task;
  • edit in src/lib/Hydra/Schema/ResultSet/TaskRetries.pm at line 92
    [3.558]
    [3.882]
    =head2 get_retryable_taskretries_row
    Fetch the next task to retry.
    =cut
    sub get_retryable_taskretries_row {
    my ($self) = @_;
    my $next_retry = $self->search(
    {
    'retry_at' => { '<=', time() }
    }, # any task
    {
    order_by => {
    -asc => 'retry_at'
    },
    rows => 1,
    }
    )->first;
    }
  • replacement in src/script/hydra-notify at line 134
    [2.220][2.220:269]()
    my $task = $taskretries->getRetryableTask();
    [2.220]
    [2.269]
    my $task = $taskretries->get_retryable_task();
  • replacement in src/script/hydra-notify at line 136
    [2.295][2.295:342]()
    $task_dispatcher->dispatchTask($task);
    [2.295]
    [3.3563]
    $task_dispatcher->dispatch_task($task);
  • edit in src/script/hydra-notify at line 138
    [3.3569][2.343:344]()
  • replacement in t/Schema/ResultSet/TaskRetries.t at line 44
    [3.2191][3.2191:2197]()
    }
    [3.2191]
    [3.595]
    };
    $taskretries->delete_all();
    };
    subtest "get_retryable_taskretries_row" => sub {
    subtest "Without any records in the database" => sub {
    is($taskretries->get_retryable_taskretries_row(), undef, "Without any records we have no tasks to retry.");
    is($taskretries->get_retryable_task(), undef, "Without any records we have no tasks to retry.");
    };
    subtest "With only tasks whose retry timestamps are in the future" => sub {
    $taskretries->create({
    channel => "bogus",
    pluginname => "bogus",
    payload => "bogus",
    attempts => 1,
    retry_at => time() + 100,
    });
    is($taskretries->get_retryable_taskretries_row(), undef, "We still have nothing to do");
    is($taskretries->get_retryable_task(), undef, "We still have nothing to do");
    };
    subtest "With tasks whose retry timestamp are in the past" => sub {
    $taskretries->create({
    channel => "build_started",
    pluginname => "bogus plugin",
    payload => "123",
    attempts => 1,
    retry_at => time() - 100,
    });
    my $row = $taskretries->get_retryable_taskretries_row();
    isnt($row, undef, "We should retry immediately");
    is($row->channel, "build_started", "Channel name should match");
    is($row->pluginname, "bogus plugin", "Plugin name should match");
    is($row->payload, "123", "Payload should match");
    is($row->attempts, 1, "We've had one attempt");
    my $task = $taskretries->get_retryable_task();
    is($task->{"event"}->{"channel_name"}, "build_started");
    is($task->{"plugin_name"}, "bogus plugin");
    is($task->{"event"}->{"payload"}, "123");
    is($task->{"record"}->get_column("id"), $row->get_column("id"));
    };