| 1 | package Hopkins::Work; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | |||
| 5 | =head1 NAME | ||
| 6 | |||
| 7 | Hopkins::Work - task queued as a unit of work | ||
| 8 | |||
| 9 | =head1 DESCRIPTION | ||
| 10 | |||
| 11 | Hopkins::Work represents an instance of a task. in other | ||
| 12 | words, it is a task that has been queued as a unit of work | ||
| 13 | ready for execution. it is eventually associated with a | ||
| 14 | database object by the store session, but can and will live | ||
| 15 | on its own without database connectivity. | ||
| 16 | |||
| 17 | =cut | ||
| 18 | |||
| 19 | use Class::Accessor::Fast; | ||
| 20 | |||
| 21 | use base 'Class::Accessor::Fast'; | ||
| 22 | |||
| 23 | __PACKAGE__->mk_accessors(qw(id worker task priority options queue output succeeded failed aborted date_enqueued date_to_execute date_started date_completed)); | ||
| 24 | |||
| 25 | sub new | ||
| 26 | { | ||
| 27 | my $self = shift->SUPER::new(@_); | ||
| 28 | |||
| 29 | $self->succeeded(0) if not defined $self->succeeded; | ||
| 30 | $self->failed(0) if not defined $self->failed; | ||
| 31 | $self->aborted(0) if not defined $self->aborted; | ||
| 32 | $self->priority(5) if not defined $self->priority; | ||
| 33 | |||
| 34 | return $self; | ||
| 35 | } | ||
| 36 | |||
| 37 | sub serialize | ||
| 38 | { | ||
| 39 | my $self = shift; | ||
| 40 | |||
| 41 | return | ||
| 42 | { | ||
| 43 | id => $self->id, | ||
| 44 | task => $self->task ? $self->task->name : undef, | ||
| 45 | queue => $self->queue->name, | ||
| 46 | priority => $self->priority, | ||
| 47 | options => $self->options, | ||
| 48 | succeeded => $self->succeeded, | ||
| 49 | failed => $self->failed, | ||
| 50 | aborted => $self->aborted, | ||
| 51 | output => $self->output, | ||
| 52 | date_enqueued => $self->date_enqueued ? $self->date_enqueued->iso8601 : undef, | ||
| 53 | date_to_execute => $self->date_to_execute->iso8601, | ||
| 54 | date_started => $self->date_started ? $self->date_started->iso8601 : undef, | ||
| 55 | date_completed => $self->date_completed ? $self->date_completed->iso8601 : undef | ||
| 56 | }; | ||
| 57 | } | ||
| 58 | |||
| 59 | =back | ||
| 60 | |||
| 61 | =head1 AUTHOR | ||
| 62 | |||
| 63 | Mike Eldridge <diz@cpan.org> | ||
| 64 | |||
| 65 | =head1 LICENSE | ||
| 66 | |||
| 67 | =cut | ||
| 68 | |||
| 69 | 1; | ||
| 70 |