@ -22,7 +22,7 @@ use strict;
use warnings;
use Anvil::Tools;
use Proc::Simple;
use Time::HiRes qw ( time sleep );
# use Time::HiRes qw ( time sleep );
use JSON;
use HTML::Strip;
use HTML::FromText;
@ -43,7 +43,7 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 1, secure =
# Connect to the database(s). If we have no connections, we'll proceed anyway as one of the 'run_once' tasks
# is to setup the database server.
$anvil->Database->connect();
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2 , secure => 0, key => "log_0132"});
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3 , secure => 0, key => "log_0132"});
# If I have no databases, sleep for a second and then exit (systemd will restart us).
if (not $anvil->data->{sys}{database}{connections})
@ -93,6 +93,16 @@ $anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 3, secure =
# This will prevent restarting while jobs are running.
$anvil->data->{sys}{jobs_running} = 0;
# Once a minute, we'll check the md5sums and see if we should restart. We don't check every loop as it places a
my $md5_interval = 60;
my $now_time = time;
my $next_check = $now_time + $md5_interval;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"s1:md5_interval" => $md5_interval,
"s2:now_time" => $now_time,
"s3:next_check" => $next_check,
}});
# These are the things we always want running.
while(1)
{
@ -103,7 +113,7 @@ while(1)
if ($anvil->data->{sys}{database}{connections})
{
# Loop and sleep for 2s.
# Run the normal tasks
keep_running($anvil);
}
else
@ -118,10 +128,26 @@ while(1)
}
# Has the file on disk changed?
if ((not $anvil->data->{sys}{jobs_running}) && ($anvil->Storage->check_md5sums))
$now_time = time;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3, list => {
"s1:now_time" => $now_time,
"s2:next_check" => $next_check,
}});
if ($now_time >= $next_check)
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "warn", key => "message_0014"});
$anvil->nice_exit({code => 1});
# Even if it is time to check, don't if a job is running.
if ((not $anvil->data->{sys}{jobs_running}) && ($anvil->Storage->check_md5sums))
{
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 0, priority => "warn", key => "message_0014"});
$anvil->nice_exit({code => 1});
}
# Update the next check time.
$next_check = $now_time + $md5_interval;
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
"s1:md5_interval" => $md5_interval,
"s2:next_check" => $next_check,
}});
}
# Exit if 'run-once' selected.
@ -279,7 +305,7 @@ sub keep_running
{
# If it's not a handle, delete it.
my $running = $anvil->data->{jobs}{handles}{$job_uuid}->poll();
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 3 , list => {
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2 , list => {
"jobs::handles::${job_uuid}" => $anvil->data->{jobs}{handles}{$job_uuid},
running => $running,
}});