Upgrading from Disbatch 3 to Disbatch 4

Preliminary steps

Configure

See Configuring

Consult /etc/disbatch/disbatch.ini for reference of current settings.

Modify your plugins:

Example new()

Disbatch 3 was called via new($queue, $parameters), with $queue containing {id => $queue_id} and $parameters containing the task's parameters.

Disbatch 4 is called via new(workerthread => $workerthread, task => $doc), with $workerthread being a Disbatch object using the plugin MongoDB user and role, and $doc being the task's document from MongoDB.

The below is from lib/Disbatch/Plugin/Demo.pm.

sub new {
    my $class = shift;

    # deprecated Disbatch 3 format
    if (ref $_[0]) {
        my ($queue, $parameters) = @_;
        warn Dumper $parameters;
        my %self = map { $_ => $parameters->{$_} } keys %$parameters;	# modifying $parameters breaks something in Disbatch 3.
        $self{queue_id} = $queue->{id};
        return bless \%self, $class;
    }

    my $self = { @_ };
    $self->{task}{params} //= $self->{task}{parameters} if defined $self->{task}{parameters};	# for deprecated Disbatch 3 format
    warn Dumper $self->{task}{params};

    # back-compat, so as to not change Disbatch 3 plugins so much
    # stick all params in $self
    for my $param (keys %{$self->{task}{params}}) {
        next if $param eq 'workerthread' or $param eq 'task';
        $self->{$param} = $self->{task}{params}{$param};
    }
    $self->{queue_id} = $self->{task}{queue};
    $self->{id} = $self->{task}{_id};

    bless $self, $class;
}