Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
class AddingPriorityFieldToQueueTasks extends CakeMigration {

/**
* Migration description
*
* @var string
*/
public $description = 'adding_priority_field_to_queue_tasks';

/**
* Actions to be performed
*
* @var array $migration
*/
public $migration = array(
'up' => array(
'create_field' => [
'queued_tasks' => [
'priority' => [
'type' => 'integer',
'null' => false,
'default' => 5,
'length' => 4
],
'indexes' => array(
'priority' => array('column' => 'priority'),
),
],
]
),
'down' => array(
'drop_field' => [
'queued_tasks' => [
'priority'
],
]
),
);

/**
* Before migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function before($direction) {
return true;
}

/**
* After migration callback
*
* @param string $direction Direction of migration process (up or down)
* @return bool Should process continue
*/
public function after($direction) {
return true;
}
}
13 changes: 12 additions & 1 deletion Model/QueuedTask.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
class QueuedTask extends QueueAppModel {

public $_next_priority = 5;

public $rateHistory = [];

public $exit = false;
Expand Down Expand Up @@ -61,6 +63,12 @@ public function initConfig() {
Configure::write('Queue', $conf);
}

public function nextPriority($priority)
{
$this->_next_priority = $priority;
return $this;
}

/**
* Add a new Job to the Queue.
*
Expand All @@ -76,8 +84,10 @@ public function createJob($jobName, $data = null, $notBefore = null, $group = nu
'jobtype' => $jobName,
'data' => serialize($data),
'group' => $group,
'reference' => $reference
'reference' => $reference,
'priority' => $this->_next_priority
];
$this->_next_priority = 5; // reset to default;
if ($notBefore !== null) {
$data['notbefore'] = date('Y-m-d H:i:s', strtotime($notBefore));
}
Expand Down Expand Up @@ -119,6 +129,7 @@ public function requestJob($capabilities, $group = null) {
'age',
],
'order' => [
'priority ASC',
'age ASC',
'id ASC'
],
Expand Down