Skip to content

Commit e07840e

Browse files
author
Symphosize
committed
Merge pull request #1 from CurtK/features/priority
Adding priority field to queued taskes, using cakeDC migrations to ad…
2 parents 1a3dfaf + a349d41 commit e07840e

2 files changed

Lines changed: 72 additions & 1 deletion

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
class AddingPriorityFieldToQueueTasks extends CakeMigration {
3+
4+
/**
5+
* Migration description
6+
*
7+
* @var string
8+
*/
9+
public $description = 'adding_priority_field_to_queue_tasks';
10+
11+
/**
12+
* Actions to be performed
13+
*
14+
* @var array $migration
15+
*/
16+
public $migration = array(
17+
'up' => array(
18+
'create_field' => [
19+
'queued_tasks' => [
20+
'priority' => [
21+
'type' => 'integer',
22+
'null' => false,
23+
'default' => 5,
24+
'length' => 4
25+
],
26+
'indexes' => array(
27+
'priority' => array('column' => 'priority'),
28+
),
29+
],
30+
]
31+
),
32+
'down' => array(
33+
'drop_field' => [
34+
'queued_tasks' => [
35+
'priority'
36+
],
37+
]
38+
),
39+
);
40+
41+
/**
42+
* Before migration callback
43+
*
44+
* @param string $direction Direction of migration process (up or down)
45+
* @return bool Should process continue
46+
*/
47+
public function before($direction) {
48+
return true;
49+
}
50+
51+
/**
52+
* After migration callback
53+
*
54+
* @param string $direction Direction of migration process (up or down)
55+
* @return bool Should process continue
56+
*/
57+
public function after($direction) {
58+
return true;
59+
}
60+
}

Model/QueuedTask.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
*/
1212
class QueuedTask extends QueueAppModel {
1313

14+
public $_next_priority = 5;
15+
1416
public $rateHistory = [];
1517

1618
public $exit = false;
@@ -61,6 +63,12 @@ public function initConfig() {
6163
Configure::write('Queue', $conf);
6264
}
6365

66+
public function nextPriority($priority)
67+
{
68+
$this->_next_priority = $priority;
69+
return $this;
70+
}
71+
6472
/**
6573
* Add a new Job to the Queue.
6674
*
@@ -76,8 +84,10 @@ public function createJob($jobName, $data = null, $notBefore = null, $group = nu
7684
'jobtype' => $jobName,
7785
'data' => serialize($data),
7886
'group' => $group,
79-
'reference' => $reference
87+
'reference' => $reference,
88+
'priority' => $this->_next_priority
8089
];
90+
$this->_next_priority = 5; // reset to default;
8191
if ($notBefore !== null) {
8292
$data['notbefore'] = date('Y-m-d H:i:s', strtotime($notBefore));
8393
}
@@ -119,6 +129,7 @@ public function requestJob($capabilities, $group = null) {
119129
'age',
120130
],
121131
'order' => [
132+
'priority ASC',
122133
'age ASC',
123134
'id ASC'
124135
],

0 commit comments

Comments
 (0)