implement begin/end for workers

This commit is contained in:
Oliver Gorwits
2012-12-16 16:08:27 +00:00
parent a852b9c093
commit 07aed68ae4
2 changed files with 51 additions and 65 deletions

View File

@@ -9,6 +9,37 @@ use Try::Tiny;
use Role::Tiny;
use namespace::clean;
sub worker_begin {
my $self = shift;
my $daemon = schema('daemon');
# deploy local db if not already done
try {
$daemon->storage->dbh_do(sub {
my ($storage, $dbh) = @_;
$dbh->selectrow_arrayref("SELECT * FROM admin WHERE 0 = 1");
});
}
catch { $daemon->deploy };
$daemon->storage->disconnect;
if ($daemon->get_db_version < $daemon->schema_version) {
$daemon->upgrade;
}
# on start, any jobs previously grabbed by a daemon on this host
# will be reset to "queued", which is the simplest way to restart them.
my $rs = schema('netdisco')->resultset('Admin')->search({
status => "running-$self->{nd_host}"
});
if ($rs->count > 0) {
$daemon->resultset('Admin')->delete;
$rs->update({status => 'queued', started => undef});
}
}
sub worker_body {
my $self = shift;