use fake row object when running job

This commit is contained in:
Oliver Gorwits
2013-01-02 19:49:50 +00:00
parent b3cd1a55e5
commit d80cc47cdb

View File

@@ -17,14 +17,20 @@ sub worker_body {
while (1) { while (1) {
my $jobs = $self->do('take_jobs', $self->wid, 'Interactive'); my $jobs = $self->do('take_jobs', $self->wid, 'Interactive');
foreach my $job (@$jobs) { foreach my $candidate (@$jobs) {
my $target = 'set_'. $job->{action}; # create a row object so we can use column accessors
# use the local db schema in case it is accidentally 'stored'
# (will throw an exception)
my $job = schema('daemon')->resultset('Admin')
->new_result($candidate);
my $target = 'set_'. $job->action;
next unless $self->can($target); next unless $self->can($target);
# do job # do job
my ($status, $log); my ($status, $log);
try { try {
$job->{started} = scalar localtime; $job->started(scalar localtime);
($status, $log) = $self->$target($job); ($status, $log) = $self->$target($job);
} }
catch { catch {
@@ -45,11 +51,11 @@ sub close_job {
try { try {
schema('netdisco')->resultset('Admin') schema('netdisco')->resultset('Admin')
->find($job->{job}) ->find($job->job)
->update({ ->update({
status => $status, status => $status,
log => $log, log => $log,
started => $job->{started}, started => $job->started,
finished => \'now()', finished => \'now()',
}); });
} }