site/templates/xbase.tmpl
site/util/bseaddimages.pl
site/util/bse_back.pl
+site/util/bse_nightly.pl
site/util/bse_notify_files.pl
site/util/bse_s3.pl
site/util/bse_session_clean.pl
a_session text,
-- so we can age this table
whenChanged timestamp
+ -- note: an index on whenChanged would speed up only the rare case
+ -- of bse_session_clean.pl, think hard before adding an index
);
-- these share data with the article table
-- last completion time
last_completion datetime null,
- -- longer description
+ -- longer description - formatted as HTML
long_desc text null
);
or die "Cannot redirect stdout: $!";
untie *STDERR;
open STDERR, ">&STDOUT" or die "Cannot redirect STDOUT: $!";
+ unless ($foreground) {
POSIX::setsid();
+ }
my $pid2 = fork;
unless (defined $pid2) {
$self->set_running(0);
$self->set_task_pid(undef);
$self->save;
- exit;
+ if ($foreground) {
+ $$msg = "Cannot start child: $!\n";
+ }
+ else {
+ exit;
+ }
}
if ($pid2) {
$task->set_last_exit($?);
$task->set_last_completion(now_sqldatetime());
$task->save;
- exit;
+ if ($foreground) {
+ return $pid2;
+ }
+ else {
+ exit;
+ }
}
else {
BSE::DB->forked;
=back
+=head2 [session cleanup]
+
+Controls the processing of the bse_session_clean.pl script.
+
+=over
+
+=item *
+
+days - the minimum age in days of sessions to be removed. Default: 30.
+
+=item *
+
+per - the number of records to remove per SQL delete request.
+Default: 1000.
+
+=item *
+
+count - the number of SQL delete requests to perform, maximum.
+Default: 1000.
+
+=item *
+
+optimize - whether to perform a table optimization after deleting
+records. Default: 1 (set to 0 to skip optimization)
+
+=back
+
+=head2 [nightly work]
+
+Controls the bse_nightly.pl script.
+
+=over
+
+=item *
+
+jobs - a comma separated list of BSE background processes to run when
+bse_nightly.pl is run. Default: bse_session_clean
+
+=back
+
=head1 AUTHOR
Tony Cook <tony@develop-help.com>
--- /dev/null
+#!/usr/bin/perl
+use strict;
+use warnings;
+use FindBin;
+use lib "$FindBin::Bin/../cgi-bin/modules";
+use BSE::API qw(bse_init bse_cfg);
+use BSE::TB::BackgroundTasks;
+use Getopt::Long;
+use Time::HiRes qw(time);
+
+my $start_time = time;
+my $verbose;
+GetOptions("v:i" => \$verbose);
+!$verbose and defined $verbose and $verbose = 1;
+
+open MYSTDOUT, ">&STDOUT" or die "Cannot dup STDOUT: $!\n";
+
+{
+ bse_init("../cgi-bin");
+ my $cfg = bse_cfg();
+
+ my $def_nightly = "bse_session_clean";
+
+ my @tasks = split /,/, $cfg->entry("nightly work", "jobs", $def_nightly);
+
+
+ TASK:
+ for my $task_id (@tasks) {
+ my $task = BSE::TB::BackgroundTasks->getByPkey($task_id);
+
+ unless ($task) {
+ warn "Unknown task id $task_id\n";
+ next TASK;
+ }
+
+ if ($task->check_running) {
+ msg(1, "$task_id is already running - skipping\n");
+ next TASK;
+ }
+
+ my $msg;
+ msg(1, "Starting $task_id\n");
+ my $pid = $task->start
+ (
+ cfg => $cfg,
+ msg => \$msg,
+ foreground => 1,
+ ) or msg(0, "Could not start $task_id: $msg\n");
+ }
+ msg(1, "Background processing complete\n");
+
+ exit;
+}
+
+sub msg {
+ my ($level, $text) = @_;
+
+ if ($level <= $verbose) {
+ my $diff = time() - $start_time;
+ printf MYSTDOUT "%.2f: %s", $diff, $text;
+ }
+}