1 package SL::BackgroundJob::Base;
5 use parent qw(Rose::Object);
7 use SL::DB::BackgroundJob;
9 sub create_standard_job {
10 my $self_or_class = shift;
11 my $cron_spec = shift;
13 my $package = ref($self_or_class) || $self_or_class;
14 $package =~ s/SL::BackgroundJob:://;
16 my %params = (cron_spec => $cron_spec || '* * * * *',
19 package_name => $package);
21 my $job = SL::DB::Manager::BackgroundJob->find_by(package_name => $params{package_name});
23 $job = SL::DB::BackgroundJob->new(%params)->update_next_run_at;
25 $job->assign_attributes(%params)->update_next_run_at;
39 SL::BackgroundJob::Base - Base class for all background jobs
43 All background jobs are derived from this class. Each job gets its own
44 class which must implement the C<run> method.
46 There are two types of background jobs: periodic jobs and jobs that
47 are run once. Periodic jobs have a CRON spec associated with them that
48 determines the points in time when the job is supposed to be run.
54 =item C<create_standard_job $cron_spec>
56 Creates or updates an entry in the database for the current job. If
57 the C<background_jobs> table contains an entry for the current class
58 (as determined by C<ref($self)>) then that entry is updated and
59 re-activated if it was disabled. Otherwise a new entry is created.
61 This function can be called both as a member or as a class function.
71 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>