1 package SL::BackgroundJob::Base;
5 use parent qw(Rose::Object);
8 use SL::DB::BackgroundJob;
9 use SL::System::Process;
11 sub get_known_job_classes {
12 tie my %dir_h, 'IO::Dir', File::Spec->catdir(File::Spec->splitdir(SL::System::Process->exe_dir), 'SL', 'BackgroundJob');
13 return sort map { s/\.pm$//; $_ } grep { m/\.pm$/ && !m/(?: ALL | Base) \.pm$/x } keys %dir_h;
16 sub create_standard_job {
17 my $self_or_class = shift;
18 my $cron_spec = shift;
20 my $package = ref($self_or_class) || $self_or_class;
21 $package =~ s/SL::BackgroundJob:://;
23 my %params = (cron_spec => $cron_spec || '* * * * *',
26 package_name => $package);
28 my $job = SL::DB::Manager::BackgroundJob->find_by(package_name => $params{package_name});
30 $job = SL::DB::BackgroundJob->new(%params)->update_next_run_at;
32 $job->assign_attributes(%params)->update_next_run_at;
46 SL::BackgroundJob::Base - Base class for all background jobs
50 All background jobs are derived from this class. Each job gets its own
51 class which must implement the C<run> method.
53 There are two types of background jobs: periodic jobs and jobs that
54 are run once. Periodic jobs have a CRON spec associated with them that
55 determines the points in time when the job is supposed to be run.
61 =item C<create_standard_job $cron_spec>
63 Creates or updates an entry in the database for the current job. If
64 the C<background_jobs> table contains an entry for the current class
65 (as determined by C<ref($self)>) then that entry is updated and
66 re-activated if it was disabled. Otherwise a new entry is created.
68 This function can be called both as a member or as a class function.
78 Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>