use Data::Dumper;
sub new {
- my ($class, $cfg, $func, $dbh) = @_;
- my $self = $class->SUPER::new($dbh, {functions => [$func]});
+ my ($class, $cfg, $dbh, $opts) = @_;
+ my $self = $class->SUPER::new($dbh, $opts);
$self->{cfg} = $cfg;
+
+ $self->{find_job_query} = sprintf('SELECT * FROM %s WHERE func IN (%s) AND enqueue_time < NOW() - INTERVAL %s SECOND ORDER BY id LIMIT %s',
+ ($opts->{table_name}||'job'),
+ join(', ', map { "'$_'" } @{$opts->{functions}}),
+ ($opts->{find_delay}||60),
+ ($opts->{job_find_size}||50),
+ );
bless $self, $class;
return $self;
}
$me->{c} = Mubot4FB::Config->new($config_name);
my $cfg = $me->{cfg} = $me->{c}->{cfg};
$me->{db} = Mubot4FB::DB->new($me->{cfg});
- $me->{queue} = Mubot4FB::Queue::Worker->new($me->{cfg}, $worker_name, $me->{db}->{dbh});
+ $me->{queue} = Mubot4FB::Queue::Worker->new($me->{cfg}, $me->{db}->{dbh}, {functions => [$worker_name]});
$me->{worker_file} = $worker_name . '.pm';
$me->{worker_file} =~ s/::/\//g;
require($me->{worker_file});