File Coverage

blib/lib/Jonk/Job.pm
Criterion Covered Total %
statement 9 43 20.9
branch 0 14 0.0
condition 0 6 0.0
subroutine 3 20 15.0
pod 12 16 75.0
total 24 99 24.2


line stmt bran cond sub pod time code
1             package Jonk::Job;
2 1     1   12 use strict;
  1         2  
  1         39  
3 1     1   6 use warnings;
  1         2  
  1         25  
4 1     1   6 use Carp ();
  1         2  
  1         1983  
5              
6             sub new {
7 0     0 0   my ($class, $jonk, $job) =@_;
8 0           bless {
9             job => $job,
10             _jonk => $jonk,
11             _completed => 0,
12             _failed => 0,
13             _aborted => 0,
14             }, $class;
15             }
16              
17             sub completed {
18 0     0 1   my $self = shift;
19              
20 0 0         Carp::croak 'job is already failed.' if $self->is_failed;
21 0 0         Carp::croak 'job is already aborted.' if $self->is_aborted;
22              
23 0           $self->{_completed} = 1;
24 0           $self->{_jonk}->_delete($self->id);
25             }
26              
27             sub failed {
28 0     0 1   my ($self, $opt) = @_;
29              
30 0 0         Carp::croak 'job is already complated.' if $self->is_completed;
31 0 0         Carp::croak 'job is already aborted.' if $self->is_aborted;
32              
33 0           $self->{_failed} = 1;
34 0           $self->{_jonk}->_failed(
35             $self->id => $opt
36             );
37             }
38              
39             sub aborted {
40 0     0 1   my $self = shift;
41              
42 0 0         Carp::croak 'job is already complated.' if $self->is_completed;
43 0 0         Carp::croak 'job is already failed.' if $self->is_failed;
44              
45 0           $self->{_aborted} = 1;
46 0           $self->{_jonk}->_delete($self->id);
47             }
48              
49 0     0 1   sub id { $_[0]->{job}->{id} }
50 0     0 1   sub func { $_[0]->{job}->{func} }
51 0     0 0   sub raw_arg { $_[0]->{job}->{arg} }
52             sub arg {
53 0     0 0   my $self = shift;
54 0           $self->{_jonk}->{functions}->{$self->func}->{deserializer}->($self->{job}->{arg});
55             }
56 0     0 1   sub enqueue_time { $_[0]->{job}->{enqueue_time} }
57 0     0 1   sub grabbed_until { $_[0]->{job}->{grabbed_until} }
58 0     0 1   sub retry_cnt { $_[0]->{job}->{retry_cnt} }
59 0     0 1   sub run_after { $_[0]->{job}->{run_after} }
60 0     0 1   sub priority { $_[0]->{job}->{priority} }
61              
62 0     0 0   sub is_completed { $_[0]->{_completed} }
63 0     0 1   sub is_failed { $_[0]->{_failed} }
64 0     0 1   sub is_aborted { $_[0]->{_aborted} }
65              
66             sub DESTROY {
67 0     0     my $self = shift;
68 0 0 0       unless ($self->is_completed or $self->is_aborted or $self->is_failed) {
      0        
69 0           Carp::cluck "job is not (complete|fail|abor)ed. this job auto failed.";
70 0           $self->failed;
71             }
72             }
73              
74             1;
75              
76             __END__