Skip to content

Commit

Permalink
Log execution delay #75
Browse files Browse the repository at this point in the history
  • Loading branch information
harai committed May 12, 2024
1 parent 09aacd0 commit 2a903fe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions inc/class-job.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ class Job
public $finished_at;
public $deleted_at;

public $execution_delay;

protected $db;
protected $table_prefix;
protected $table;
Expand Down Expand Up @@ -115,6 +117,9 @@ public function acquire_lock()
$started_at = new DateTime('now', new DateTimeZone('UTC'));
$this->started_at = $started_at->format(MYSQL_DATE_FORMAT);

$nextrun = DateTime::createFromFormat('Y-m-d H:i:s', $this->nextrun, new DateTimeZone('UTC'));
$this->execution_delay = $started_at->getTimestamp() - $nextrun->getTimestamp();

$res = $this->db->prepare_query(
"UPDATE `$this->table`
SET `status` = 'running', `started_at` = :started_at
Expand Down
6 changes: 4 additions & 2 deletions inc/class-runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ public function run()

$this->hooks->run('Runner.run.before');

$prev_cleanup = time();
$prev_cleanup = 0;
try {
while (true) {
pcntl_signal_dispatch();
Expand Down Expand Up @@ -621,7 +621,9 @@ protected function run_job($job)
$worker = new Worker($process, $pipes, $job, $this->log, $error_log_file, $this->max_log_size);
$this->workers[] = $worker;

$this->log->debug('worker started', $job->log_values());
$this->log->debug('worker started', $job->log_values() + [
'execution_delay' => $job->execution_delay,
]);
$this->hooks->run('Runner.run_job.started', $worker, $job);
}

Expand Down

0 comments on commit 2a903fe

Please sign in to comment.