File Coverage

blib/lib/TheSchwartz/JobScheduler/Job.pm
Criterion Covered Total %
statement 21 21 100.0
branch 11 18 61.1
condition n/a
subroutine 4 4 100.0
pod 1 1 100.0
total 37 44 84.0


line stmt bran cond sub pod time code
1             package TheSchwartz::JobScheduler::Job;
2             ## no critic (ControlStructures::ProhibitPostfixControls)
3              
4 7     7   180805 use strict;
  7         17  
  7         286  
5 7     7   34 use warnings;
  7         14  
  7         575  
6              
7             # ABSTRACT: TheSchwartz Job class
8              
9             our $VERSION = '0.002'; # VERSION: generated by DZP::OurPkgVersion
10              
11 7     7   661 use Moo;
  7         10616  
  7         48  
12              
13             sub as_hashref {
14 14     14 1 46 my $self = shift;
15              
16 14         27 my %data;
17 14 50       66 $data{jobid} = $self->jobid if ( defined $self->jobid );
18 14 50       96 $data{funcid} = $self->funcid if ( defined $self->funcid );
19 14 50       105 $data{arg} = $self->arg if ( defined $self->arg );
20 14 100       87 $data{uniqkey} = $self->uniqkey if ( defined $self->uniqkey );
21 14 50       72 $data{insert_time} = $self->insert_time if ( defined $self->insert_time );
22 14 50       126 $data{run_after} = $self->run_after if ( defined $self->run_after );
23 14 50       133 $data{grabbed_until} = $self->grabbed_until if ( defined $self->grabbed_until );
24 14 100       84 $data{priority} = $self->priority if ( defined $self->priority );
25 14 50       51 $data{coalesce} = $self->coalesce if ( defined $self->coalesce );
26              
27 14         57 return \%data;
28             }
29              
30             has jobid => ( is => 'rw', default => sub { undef }, );
31             has funcid => ( is => 'rw', default => sub { undef }, );
32             has arg => ( is => 'rw', default => sub { undef }, );
33             has uniqkey => ( is => 'rw', default => sub { undef }, );
34             has insert_time => ( is => 'rw', default => sub { undef }, );
35             has run_after => ( is => 'rw', default => sub { time }, );
36             has grabbed_until => ( is => 'rw', default => sub { 0 }, );
37             has priority => ( is => 'rw', default => sub { undef }, );
38             has coalesce => ( is => 'rw', default => sub { undef }, );
39             has funcname => ( is => 'rw', default => sub { undef }, );
40              
41             1;
42              
43             __END__
44              
45             =pod
46              
47             =encoding UTF-8
48              
49             =head1 NAME
50              
51             TheSchwartz::JobScheduler::Job - TheSchwartz Job class
52              
53             =head1 VERSION
54              
55             version 0.002
56              
57             =head1 SYNOPSIS
58              
59             use TheSchwartz::JobScheduler::Job;
60              
61             my $job1 = TheSchwartz::JobScheduler::Job->new;
62             $job1->funcname("WorkerName");
63             $job1->arg({ foo => "bar" });
64             $job1->uniqkey("uniqkey");
65             $job1->run_after( time + 60 );
66              
67             my $job2 = TheSchwartz::JobScheduler::Job->new(
68             funcname => 'WorkerName',
69             arg => { foo => 'baz' },
70             );
71              
72             =head1 DESCRIPTION
73              
74             The Job class makes it easier to create TheSchwartz jobs with different parameters.
75              
76             =head1 METHODS
77              
78             =head2 as_hashref
79              
80             Get Job as a hashref.
81              
82             Accessors:
83              
84             =over 8
85              
86             =item jobid
87              
88             =item funcid
89              
90             =item arg
91              
92             =item uniqkey
93              
94             =item insert_time
95              
96             =item run_after
97              
98             =item grabbed_until
99              
100             =item priority
101              
102             =item coalesce
103              
104             =item funcname
105              
106             =back
107              
108             =head1 AUTHOR
109              
110             Mikko Koivunalho <mikkoi@cpan.org>
111              
112             =head1 COPYRIGHT AND LICENSE
113              
114             This software is copyright (c) 2023 by Mikko Koivunalho.
115              
116             This is free software; you can redistribute it and/or modify it under
117             the same terms as the Perl 5 programming language system itself.
118              
119             =cut