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

Commit

Permalink
Switched Codeformatter to ZendStudio 7.2.x
Browse files Browse the repository at this point in the history
No Content Changes.
  • Loading branch information
MSeven committed May 1, 2010
1 parent 2049ec6 commit d1650c6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 48 deletions.
2 changes: 1 addition & 1 deletion config/sql/queue.php
Expand Up @@ -16,7 +16,7 @@ function before($event = array()) {

function after($event = array()) {
}

public $queued_tasks = array(
'id' => array(
'type' => 'integer',
Expand Down
12 changes: 6 additions & 6 deletions models/queued_task.php
Expand Up @@ -8,11 +8,11 @@
* @link http://github.com/MSeven/cakephp_queue
*/
class QueuedTask extends AppModel {

public $name = 'QueuedTask';

public $rateHistory = array();

public $exit = false;

/**
Expand All @@ -23,7 +23,7 @@ class QueuedTask extends AppModel {
* @return bool success
*/
public function createJob($jobName, $data, $notBefore = null) {

$data = array(
'jobtype' => $jobName,
'data' => serialize($data)
Expand All @@ -47,7 +47,7 @@ public function onError() {
public function requestJob($capabilities) {
$idlist = array();
$wasFetched = array();

$findConf = array(
'conditions' => array(
'completed' => null,
Expand Down Expand Up @@ -219,7 +219,7 @@ public function cleanOldJobs() {
$this->deleteAll(array(
'completed < ' => date('Y-m-d H:i:s', time() - Configure::read('queue.cleanuptimeout'))
));

}

}
Expand Down
54 changes: 27 additions & 27 deletions tests/cases/models/queued_task.test.php
Expand Up @@ -54,16 +54,16 @@ public function testQueueInstance() {
public function testCreateAndCount() {
// at first, the queue should contain 0 items.
$this->assertEqual(0, $this->QueuedTask->getLength());

// create a job
$this->assertTrue($this->QueuedTask->createJob('test1', array(
'some' => 'random',
'test' => 'data'
)));

// test if queue Length is 1 now.
$this->assertEqual(1, $this->QueuedTask->getLength());

//create some more jobs
$this->assertTrue($this->QueuedTask->createJob('test2', array(
'some' => 'random',
Expand All @@ -77,10 +77,10 @@ public function testCreateAndCount() {
'some' => 'random',
'test' => 'data4'
)));

//overall queueLength shpould now be 4
$this->assertEqual(4, $this->QueuedTask->getLength());

// there should be 1 task of type 'test1', one of type 'test3' and 2 of type 'test2'
$this->assertEqual(1, $this->QueuedTask->getLength('test1'));
$this->assertEqual(2, $this->QueuedTask->getLength('test2'));
Expand All @@ -103,7 +103,7 @@ public function testCreateAndFetch() {
'x4' => 'y4'
);
// start off empty.


$this->assertEqual(array(), $this->QueuedTask->find('all'));
// at first, the queue should contain 0 items.
Expand All @@ -112,21 +112,21 @@ public function testCreateAndFetch() {
$this->assertFalse($this->QueuedTask->requestJob($capabilities));
// insert one job.
$this->assertTrue($this->QueuedTask->createJob('task1', $testData));

// fetch and check the first job.
$data = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual(1, $data['id']);
$this->assertEqual('task1', $data['jobtype']);
$this->assertEqual(0, $data['failed']);
$this->assertNull($data['completed']);
$this->assertEqual($testData, unserialize($data['data']));

// after this job has been fetched, it may not be reassigned.
$this->assertEqual(array(), $this->QueuedTask->requestJob($capabilities));

// queue length is still 1 since the first job did not finish.
$this->assertEqual(1, $this->QueuedTask->getLength());

// Now mark Task1 as done
$this->assertTrue($this->QueuedTask->markJobDone(1));
// Should be 0 again.
Expand Down Expand Up @@ -156,7 +156,7 @@ public function testSequence() {
}
// 10 jobs in the queue.
$this->assertEqual(10, $this->QueuedTask->getLength());

// jobs should be fetched in the original sequence.
foreach (range(0, 4) as $num) {
$job = $this->QueuedTask->requestJob($capabilities);
Expand All @@ -168,7 +168,7 @@ public function testSequence() {
$this->assertTrue($this->QueuedTask->markJobDone($num + 1));
$this->assertEqual(9 - $num, $this->QueuedTask->getLength());
}

// jobs should be fetched in the original sequence.
foreach (range(5, 9) as $num) {
$job = $this->QueuedTask->requestJob($capabilities);
Expand Down Expand Up @@ -217,7 +217,7 @@ public function testNotBeforeOrder() {
$this->assertTrue($this->QueuedTask->createJob('task1', 'three', '- 3 Seconds'));
$this->assertTrue($this->QueuedTask->createJob('task1', 'two', '- 4 Seconds'));
$this->assertTrue($this->QueuedTask->createJob('task1', 'one', '- 5 Seconds'));

// when usin requestJob, the jobs we just created should be delivered in this order, NOT the order in which they where created.
$expected = array(
array(
Expand All @@ -241,7 +241,7 @@ public function testNotBeforeOrder() {
'data' => ''
)
);

foreach ($expected as $item) {
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($item['name'], $tmp['jobtype']);
Expand All @@ -267,59 +267,59 @@ public function testRateLimit() {
'retries' => 2
)
);

// clear out the rate history
$this->QueuedTask->rateHistory = array();

$this->assertTrue($this->QueuedTask->createJob('task1', '1'));
$this->assertTrue($this->QueuedTask->createJob('task1', '2'));
$this->assertTrue($this->QueuedTask->createJob('task1', '3'));
$this->assertTrue($this->QueuedTask->createJob('dummytask', null));
$this->assertTrue($this->QueuedTask->createJob('dummytask', null));
$this->assertTrue($this->QueuedTask->createJob('dummytask', null));
$this->assertTrue($this->QueuedTask->createJob('dummytask', null));

//At first we get task1-1.
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'task1');
$this->assertEqual(unserialize($tmp['data']), '1');

//The rate limit should now skip over task1-2 and fetch a dummytask.
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'dummytask');
$this->assertEqual(unserialize($tmp['data']), null);

//and again.
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'dummytask');
$this->assertEqual(unserialize($tmp['data']), null);

//Then some time passes
sleep(1);

//Now we should get task1-2
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'task1');
$this->assertEqual(unserialize($tmp['data']), '2');

//and again rate limit to dummytask.
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'dummytask');
$this->assertEqual(unserialize($tmp['data']), null);

//Then some more time passes
sleep(1);

//Now we should get task1-3
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'task1');
$this->assertEqual(unserialize($tmp['data']), '3');

//and again rate limit to dummytask.
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'dummytask');
$this->assertEqual(unserialize($tmp['data']), null);

//and now the queue is empty
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp, null);
Expand All @@ -334,7 +334,7 @@ public function testRequeueAfterTimeout() {
'rate' => 0
)
);

$this->assertTrue($this->QueuedTask->createJob('task1', '1'));
$tmp = $this->QueuedTask->requestJob($capabilities);
$this->assertEqual($tmp['jobtype'], 'task1');
Expand Down
18 changes: 9 additions & 9 deletions vendors/shells/queue.php
Expand Up @@ -17,7 +17,7 @@ class queueShell extends Shell {
* @var QueuedTask
*/
public $QueuedTask;

private $taskConf;

/**
Expand All @@ -26,7 +26,7 @@ class queueShell extends Shell {
public function initialize() {
App::import('Folder');
$this->_loadModels();

foreach ($this->Dispatch->shellPaths as $path) {
$folder = new Folder($path . DS . 'tasks');
$this->tasks = array_merge($this->tasks, $folder->find('queue_.*\.php'));
Expand All @@ -35,10 +35,10 @@ public function initialize() {
foreach ($this->tasks as &$task) {
$task = basename($task, '.php');
}

//Config can be overwritten via local app config.
Configure::load('queue');

$conf = Configure::read('queue');
if (!is_array($conf)) {
$conf = array();
Expand Down Expand Up @@ -93,7 +93,7 @@ public function add() {
$this->out('Please call like this:');
$this->out(' cake queue add <taskname>');
} else {

if (in_array($this->args[0], $this->taskNames)) {
$this->{$this->args[0]}->add();
} elseif (in_array('queue_' . $this->args[0], $this->taskNames)) {
Expand All @@ -116,7 +116,7 @@ public function add() {
public function runworker() {
$exit = false;
$starttime = time();

while (!$exit) {
$this->out('Looking for Job....');
$data = $this->QueuedTask->requestJob($this->getTaskConf());
Expand All @@ -138,7 +138,7 @@ public function runworker() {
$this->out('nothing to do, sleeping.');
sleep(Configure::read('queue.sleeptime'));
}

// check if we are over the maximum runtime and end processing if so.
if (Configure::read('queue.workermaxruntime') != 0 && (time() - $starttime) >= Configure::read('queue.workermaxruntime')) {
$exit = true;
Expand Down Expand Up @@ -168,9 +168,9 @@ public function clean() {
*/
public function stats() {
$this->out('Jobs currenty in the Queue:');

$types = $this->QueuedTask->getTypes();

foreach ($types as $type) {
$this->out(" " . str_pad($type, 20, ' ', STR_PAD_RIGHT) . ": " . $this->QueuedTask->getLength($type));
}
Expand Down
3 changes: 0 additions & 3 deletions vendors/shells/tasks/queue_email.php
@@ -1,5 +1,4 @@
<?php

/**
* @author MGriesbach@gmail.com
* @package QueuePlugin
Expand Down Expand Up @@ -28,7 +27,6 @@ class queueEmailTask extends Shell {
'additionalParams' => '',
'layout' => 'default'
);

public $timeout = 120;
public $retries = 0;
/**
Expand All @@ -37,7 +35,6 @@ class queueEmailTask extends Shell {
* @var Controller
*/
public $Controller;

/**
* EmailComponent
*
Expand Down
4 changes: 2 additions & 2 deletions vendors/shells/tasks/queue_example.php
Expand Up @@ -21,14 +21,14 @@ class queueExampleTask extends Shell {
public $uses = array(
'Queue.QueuedTask'
);

/**
* ZendStudio Codecomplete Hint
*
* @var QueuedTask
*/
public $QueuedTask;

/**
* Timeout für run, after which the Task is reassigned to a new worker.
*
Expand Down

0 comments on commit d1650c6

Please sign in to comment.