Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 782fd788

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 782fd7884fb686cd2e336756dadeb4ab5d05a415
  • Vorgänger 295e585a
  • Nachfolger 03fc848d

BackgroundJob-Hilfsfunktionen

Unterschiede anzeigen:

SL/DB/BackgroundJob.pm
1
# This file has been auto-generated only because it didn't exist.
2
# Feel free to modify it at will; it will not be overwritten automatically.
3

  
4 1
package SL::DB::BackgroundJob;
5 2

  
6 3
use strict;
7 4

  
5
use DateTime::Event::Cron;
6

  
8 7
use SL::DB::MetaSetup::BackgroundJob;
8
use SL::DB::Manager::BackgroundJob;
9

  
10
sub update_next_run_at {
11
  my $self = shift;
9 12

  
10
# Creates get_all, get_all_count, get_all_iterator, delete_all and update_all.
11
__PACKAGE__->meta->make_manager_class;
13
  my $cron = DateTime::Event::Cron->new_from_cron($self->cron_spec || '* * * * *');
14
  $self->update_attributes(next_run_at => $cron->next->set_time_zone($::locale->get_local_time_zone));
15
  return $self;
16
}
12 17

  
13 18
1;
SL/DB/Manager/BackgroundJob.pm
1
package SL::DB::Manager::BackgroundJob;
2

  
3
use strict;
4

  
5
use SL::DB::Helpers::Manager;
6
use base qw(SL::DB::Helpers::Manager);
7

  
8
sub object_class { 'SL::DB::BackgroundJob' }
9

  
10
__PACKAGE__->make_manager_methods;
11

  
12
sub cleanup {
13
  my $class = shift;
14
  $class->delete_all(where => [ and => [ type => 'once', last_run_at => { lt => DateTime->now_local->subtract(days => '1') } ] ]);
15
}
16

  
17
sub get_all_need_to_run {
18
  my $class = shift;
19
  return $class->get_all(where => [ and => [ active => 1, next_run_at => { le => DateTime->now_local } ] ]);
20
}
21

  
22
1;

Auch abrufbar als: Unified diff