Skip to content

Commit

Permalink
Queue debugger. See: wpsharks/comment-mail#317
Browse files Browse the repository at this point in the history
  • Loading branch information
jaswsinc committed Nov 17, 2016
1 parent 526342a commit 3629665
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/includes/classes/QueueProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ class QueueProcessor extends AbsBase
*/
protected $max_time;

/**
* @var int Time limit (in seconds).
*
* @since 161116
*/
protected $time_limit;

/**
* @var int Delay (in milliseconds).
*
Expand Down Expand Up @@ -183,9 +190,9 @@ protected function maybePrepCronJob()

// The following may not work, but we can try :-)
if ($this->delay) { // Allow some extra time for the delay?
@set_time_limit(min(300, ceil($this->max_time + ($this->delay / 1000) + 30)));
@set_time_limit($this->time_limit = min(300, ceil($this->max_time + ($this->delay / 1000) + 30)));
} else {
@set_time_limit(min(300, $this->max_time + 30));
@set_time_limit($this->time_limit = min(300, $this->max_time + 30));
}
}

Expand All @@ -202,14 +209,30 @@ protected function maybeProcess()
if (!$this->plugin->options['queue_processing_enable']) {
return; // Disabled currently.
}
$log = 'Version: '.VERSION."\n";
$log .= 'Is CRON: '.($this->is_cron ? 'true' : 'false')."\n";
$log .= 'Start Time: '.date(DATE_RFC822, $this->start_time)."\n";
$log .= 'Time Limit: '.$this->time_limit."\n";
$log .= 'Max Limit: '.$this->max_limit."\n";
$log .= 'Max Time: '.$this->max_time."\n";
$log .= 'Delay: '.$this->delay."\n";

file_put_contents(WP_CONTENT.'/cm-debug.log', $log, FILE_APPEND);

if (!($this->entries = $this->entries())) {
return; // Nothing to do.
}
$this->total_entries = count($this->entries);

$log = 'Total Entries: '.$this->total_entries."\n";
file_put_contents(WP_CONTENT.'/cm-debug.log', $log, FILE_APPEND);

$deleted_entries = 0;

foreach ($this->entries as $_entry_id_key => $_entry) {
if ($this->processEntry($_entry)) {
$this->deleteEntry($_entry);
++$deleted_entries;
} // Do not delete those being held over.
// See: <https://github.com/websharks/comment-mail/issues/173>

Expand All @@ -218,8 +241,13 @@ protected function maybeProcess()
if ($this->isOutOfTime() || $this->isDelayOutOfTime()) {
break; // Out of time now; or after a possible delay.
}
}
unset($_entry_id_key, $_entry); // Housekeeping.
} // unset($_entry_id_key, $_entry); // Housekeeping.

$log = 'End Time: '.date(DATE_RFC822, time())."\n";
$log .= 'Deleted Entry Counter: '.$deleted_entries."\n";
$log .= 'Processed Entry Counter: '.$this->processed_entry_counter."\n";

file_put_contents(WP_CONTENT.'/cm-debug.log', $log."\n", FILE_APPEND);
}

/**
Expand Down

0 comments on commit 3629665

Please sign in to comment.