6 unshift @INC, "modules/override"; # Use our own versions of various modules (e.g. YAML).
7 push @INC, "modules/fallback"; # Only use our own versions of modules if there's no system version.
10 use CGI qw( -no_xhtml);
16 use English qw(-no_match_vars);
18 use SL::DB::BackgroundJob;
19 use SL::BackgroundJob::ALL;
21 use SL::Helper::DateTime;
27 # this is a cleaned up version of am.pl
28 # it lacks redirection, some html setup and most of the authentication process.
29 # it is assumed that anyone with physical access and execution rights on this script
30 # won't be hindered by authentication anyway.
32 my $login = $config{task_server}->{login};
37 $::userspath = "users";
38 $::templates = "templates";
39 $::sendmail = "| /usr/sbin/sendmail -t";
42 eval { require "config/lx-erp.conf"; 1; } or die $EVAL_ERROR;
43 eval { require "config/lx-erp-local.conf"; 1; } or die $EVAL_ERROR if -f "config/lx-erp-local.conf";
45 $::lxdebug = LXDebug->new;
46 $::locale = Locale->new($::language);
47 $::cgi = CGI->new qw();
49 $::auth = SL::Auth->new;
51 die 'cannot reach auth db' unless $::auth->session_tables_present;
53 $::auth->restore_session;
55 require "bin/mozilla/common.pl";
57 die "cannot find user $login" unless %::myconfig = $::auth->read_user($login);
58 die "cannot find locale for user $login" unless $::locale = Locale->new('de');
64 read_config $self->{configfile} => %config;
66 die "Missing section [task_server] in config file" unless $config{task_server};
67 die "Missing key 'login' in section [task_server] in config file" unless $config{task_server}->{login};
77 $::lxdebug->message(0, "Retrieving jobs") if $config{task_server}->{debug};
79 my $jobs = SL::DB::Manager::BackgroundJob->get_all_need_to_run;
81 $::lxdebug->message(0, " Found: " . join(' ', map { $_->package_name } @{ $jobs })) if $config{task_server}->{debug} && @{ $jobs };
83 $_->run for @{ $jobs };
88 if ($config{task_server}->{debug}) {
89 $::lxdebug->message(0, "Exception during execution: ${EVAL_ERROR}") if !$ok;
90 $::lxdebug->message(0, "Sleeping");
93 my $seconds = 60 - (localtime)[0];
94 sleep($seconds < 30 ? $seconds + 60 : $seconds);
99 my $pidbase = "${cwd}/users/pid";
101 mkdir($pidbase) if !-d $pidbase;
103 newdaemon(configfile => "${cwd}/config/task_server.conf",
104 progname => 'lx-office-task-server',
105 pidbase => "${pidbase}/",