Skip to content
This repository has been archived by the owner on May 27, 2019. It is now read-only.

Commit

Permalink
Fixes Issue #3 (configureable cleanup timeout)
Browse files Browse the repository at this point in the history
Readme Updates
Slightly optimized stats display.
  • Loading branch information
MSeven committed Sep 8, 2009
1 parent 441270b commit bbcb965
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 8 deletions.
7 changes: 7 additions & 0 deletions README
@@ -1,6 +1,7 @@
--------------------------------
CakePHP Queue Plugin
--------------------------------
http://github.com/MSeven/cakephp_queue

Background:
--------------------------------
Expand Down Expand Up @@ -47,6 +48,9 @@ $config['queue']['defaultworkerretries'] = 4;
#Seconds of runnig time after which the worker will terminate (0 = unlimited)
$config['queue']['workermaxruntime'] = 0;

#Seconds after which finished jobs may be cleaned from the jobTable
$config['queue']['cleanuptimeout'] = 2000;

The values above are the default settings which apply, when no configuration is found.

Usage:
Expand All @@ -71,3 +75,6 @@ Custom tasks should be placed in <yourapp>/vendors/shells/tasks.
Tasks should be named 'queue_something.php' and implement a "queueSomethingTask", keeping Cakephp Naming conventions intact.

A detailed Example task can be found in /vendors/shells/tasks/queue_example.php inside this folder.

Current releases: http://github.com/MSeven/cakephp_queue/downloads
Documentation: http://wiki.github.com/MSeven/cakephp_queue
8 changes: 6 additions & 2 deletions models/queued_task.php
Expand Up @@ -168,10 +168,14 @@ public function getTypes() {
return $this->find('list', $findConf);
}

/**
* Return some statistics about finished jobs still in the Database.
* @return array
*/
public function getStats() {
$findConf = array(
'fields' => array(
'jobtype, AVG(UNIX_TIMESTAMP(completed)-UNIX_TIMESTAMP(created)) AS alltime, AVG(UNIX_TIMESTAMP(completed)-UNIX_TIMESTAMP(fetched)) AS runtime, AVG(UNIX_TIMESTAMP(fetched)-IF(notbefore is null,UNIX_TIMESTAMP(created),UNIX_TIMESTAMP(notbefore))) AS fetchdelay'
'jobtype,count(id) as num, AVG(UNIX_TIMESTAMP(completed)-UNIX_TIMESTAMP(created)) AS alltime, AVG(UNIX_TIMESTAMP(completed)-UNIX_TIMESTAMP(fetched)) AS runtime, AVG(UNIX_TIMESTAMP(fetched)-IF(notbefore is null,UNIX_TIMESTAMP(created),UNIX_TIMESTAMP(notbefore))) AS fetchdelay'
),
'conditions' => array(
'completed NOT' => null
Expand All @@ -189,7 +193,7 @@ public function getStats() {
*/
public function cleanOldJobs() {
$this->deleteAll(array(
'completed < ' => date('Y-m-d H:i:s', time() - 2000)
'completed < ' => date('Y-m-d H:i:s', time() - Configure::read('queue.cleanuptimeout'))
));

}
Expand Down
26 changes: 20 additions & 6 deletions vendors/shells/queue.php
Expand Up @@ -49,7 +49,8 @@ public function initialize() {
'gcprop' => 10,
'defaultworkertimeout' => 120,
'defaultworkerretries' => 4,
'workermaxruntime' => 0
'workermaxruntime' => 0,
'cleanuptimeout' => 2000
), $conf));
}

Expand Down Expand Up @@ -147,11 +148,19 @@ public function runworker() {
}
}

/**
* Manually trigger a Finished job cleanup.
* @return null
*/
public function clean() {
$this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - 2000));
$this->out('Deleting old jobs, that have finished before ' . date('Y-m-d H:i:s', time() - Configure::read('queue.cleanuptimeout')));
$this->QueuedTask->cleanOldJobs();
}

/**
* Display Some statistics about Finished Jobs.
* @return null
*/
public function stats() {
$this->out('Jobs currenty in the Queue:');

Expand All @@ -161,18 +170,23 @@ public function stats() {
$this->out(" " . str_pad($type, 20, ' ', STR_PAD_RIGHT) . ": " . $this->QueuedTask->getLength($type));
}
$this->hr();
$this->out('Total Jobs : ' . $this->QueuedTask->getLength());
$this->out('Total unfinished Jobs : ' . $this->QueuedTask->getLength());
$this->hr();
$this->out('Finished Job Statistics:');
$data = $this->QueuedTask->getStats();
foreach ($data as $item) {
$this->out(" " . $item['QueuedTask']['jobtype'] . ": ");
$this->out(" Average Job existence : " . $item[0]['alltime'] . 's');
$this->out(" Average Execution delay: " . $item[0]['fetchdelay'] . 's');
$this->out(" Average Execution time : " . $item[0]['runtime'] . 's');
$this->out(" Finished Jobs in Database: " . $item[0]['num']);
$this->out(" Average Job existence : " . $item[0]['alltime'] . 's');
$this->out(" Average Execution delay : " . $item[0]['fetchdelay'] . 's');
$this->out(" Average Execution time : " . $item[0]['runtime'] . 's');
}
}

/**
* Returns a List of available QueueTasks and their individual configurations.
* @return array
*/
private function getTaskConf() {
if (!is_array($this->taskConf)) {
$this->taskConf = array();
Expand Down

0 comments on commit bbcb965

Please sign in to comment.