diff --git a/advancedqueue.css b/advancedqueue.css deleted file mode 100644 index d594125..0000000 --- a/advancedqueue.css +++ /dev/null @@ -1,31 +0,0 @@ - -.advancedqueue-status-queued, -.advancedqueue-status-processing, -.advancedqueue-status-processed, -.advancedqueue-status-failed { - display: inline-block; - height: 12px; - line-height: 12px; - padding-left: 16px; - width: 6em; - - background-position: 0% 50%; - background-repeat: no-repeat; -} - -.advancedqueue-status-queued { - background-image: url('images/queued.gif'); -} -.advancedqueue-status-processing { - background-image: url('images/processing.gif'); -} -.advancedqueue-status-processed { - background-image: url('images/processed.png'); - color: #336633; - font-weight: bold; -} -.advancedqueue-status-failed { - background-image: url('images/failed.png'); - color: #ff0000; - font-weight: bold; -} diff --git a/advancedqueue.info b/advancedqueue.info index ace3a37..7697e17 100644 --- a/advancedqueue.info +++ b/advancedqueue.info @@ -9,3 +9,6 @@ files[] = advancedqueue.queue.inc files[] = views/advancedqueue_handler_field_title.inc files[] = views/advancedqueue_handler_field_status.inc files[] = views/advancedqueue_handler_filter_status.inc + +; Test +files[] = tests/advancedqueue.test diff --git a/advancedqueue.install b/advancedqueue.install index e29b44f..8295cad 100644 --- a/advancedqueue.install +++ b/advancedqueue.install @@ -1,27 +1,32 @@ array( 'type' => 'int', 'not null' => TRUE, - 'default' => -1, + 'default' => ADVANCEDQUEUE_STATUS_QUEUED, 'size' => 'tiny', 'description' => 'Indicates whether the item has been processed (-1 = queue, 0 = processing, 1 = successfully processed, 2 = failed).', ), diff --git a/advancedqueue.module b/advancedqueue.module index 6f13541..16c9450 100644 --- a/advancedqueue.module +++ b/advancedqueue.module @@ -1,6 +1,31 @@ time(), - 'status' => -1, + 'status' => ADVANCEDQUEUE_STATUS_QUEUED, )); return (bool) $query->execute(); } @@ -50,7 +54,7 @@ class AdvancedQueue implements DrupalReliableQueueInterface { // should really expire. $update = db_update('advancedqueue') ->fields(array( - 'status' => 0, + 'status' => ADVANCEDQUEUE_STATUS_PROCESSING, 'expire' => time() + $lease_time, )) ->condition('item_id', $item->item_id) @@ -72,7 +76,7 @@ class AdvancedQueue implements DrupalReliableQueueInterface { $update = db_update('advancedqueue') ->fields(array( 'expire' => 0, - 'status' => -1, + 'status' => ADVANCEDQUEUE_STATUS_QUEUED, )) ->condition('item_id', $item->item_id); return $update->execute(); @@ -82,7 +86,7 @@ class AdvancedQueue implements DrupalReliableQueueInterface { db_update('advancedqueue') ->fields(array( 'expire' => 0, - 'status' => isset($item->status) ? $item->status : 1, + 'status' => isset($item->status) ? $item->status : ADVANCEDQUEUE_STATUS_SUCCESS, 'result' => serialize(isset($item->result) ? $item->result : array()), 'processed' => time(), )) diff --git a/advancedqueue_example/advancedqueue_example.module b/advancedqueue_example/advancedqueue_example.module index 92beeb8..9c62f30 100644 --- a/advancedqueue_example/advancedqueue_example.module +++ b/advancedqueue_example/advancedqueue_example.module @@ -31,6 +31,7 @@ function advancedqueue_example_worker($item, $end_time = FALSE) { '@time' => date('r', $data['timestamp']), ); drush_print(dt('The "worker" is now processing a example task number @id for user ID @uid created at @time.', $params)); + return TRUE; } /** diff --git a/css/advancedqueue.css b/css/advancedqueue.css new file mode 100644 index 0000000..d594125 --- /dev/null +++ b/css/advancedqueue.css @@ -0,0 +1,31 @@ + +.advancedqueue-status-queued, +.advancedqueue-status-processing, +.advancedqueue-status-processed, +.advancedqueue-status-failed { + display: inline-block; + height: 12px; + line-height: 12px; + padding-left: 16px; + width: 6em; + + background-position: 0% 50%; + background-repeat: no-repeat; +} + +.advancedqueue-status-queued { + background-image: url('images/queued.gif'); +} +.advancedqueue-status-processing { + background-image: url('images/processing.gif'); +} +.advancedqueue-status-processed { + background-image: url('images/processed.png'); + color: #336633; + font-weight: bold; +} +.advancedqueue-status-failed { + background-image: url('images/failed.png'); + color: #ff0000; + font-weight: bold; +} diff --git a/drush/advancedqueue.drush.inc b/drush/advancedqueue.drush.inc index 5732e60..ee5a8c3 100644 --- a/drush/advancedqueue.drush.inc +++ b/drush/advancedqueue.drush.inc @@ -2,11 +2,11 @@ /** * @file - * Drush worker for Advanced queues. + * Drush worker for Advanced-queue. */ /** - * Implementation of hook_drush_command(). + * Implements hook_drush_command(). */ function advancedqueue_drush_command() { $items = array(); @@ -16,9 +16,10 @@ function advancedqueue_drush_command() { 'queue' => dt('The name of the queue to process.'), ), 'options' => array( - 'timeout' => 'The maximum execution time of the script.', + 'timeout' => 'The maximum execution time of the script. Be warned that this is a rough estimate as the time is only checked between two items.', 'all' => 'Process all queues.', ), + 'aliases' => array('advancedqueue'), ); return $items; } @@ -99,7 +100,7 @@ function drush_advancedqueue_process_item($queue, $queue_name, $queue_info, $ite $params = array( '@queue' => $queue_name, '@id' => $item->item_id, - '@title' => $item->title ? $item->title : dt('untitled'), + '@title' => !empty($item->title) ? $item->title : dt('untitled'), ); drush_log(dt('[@queue:@id] Starting processing item @title.', $params)); @@ -108,25 +109,24 @@ function drush_advancedqueue_process_item($queue, $queue_name, $queue_info, $ite // callback. $output = $function($item, $end_time); if (is_array($output)) { - $item->status = $output[0]; - $item->result = $output[1]; + $item->status = $output['status']; + $item->result = $output['result']; } else { - // TODO: remove magic constants. - $item->status = $output ? 1 : 2; + $item->status = $output ? ADVANCEDQUEUE_STATUS_SUCCESS : ADVANCEDQUEUE_STATUS_FAILURE; } } catch (Exception $e) { + $item->status = ADVANCEDQUEUE_STATUS_FAILURE; $params['!message'] = (string) $e; drush_log(dt('[!queue:!id] failed processing: !message', $params)); - // TODO: remove magic constants. - $item->status = 2; } drush_log(dt('[@queue:@id] Processing ended.', $params)); if ($queue_info['delete when completed']) { - // Item was processed, so we can delete it. + // Item was processed, so we can "delete" it. This is not removing the + // item from the database, but rather updates it with the status. $queue->deleteItem($item); } } diff --git a/tests/advancedqueue.test b/tests/advancedqueue.test new file mode 100644 index 0000000..119d305 --- /dev/null +++ b/tests/advancedqueue.test @@ -0,0 +1,21 @@ + 'Advanced queue', + 'description' => 'Validate that a Advanced Queue works as a normal queue.', + 'group' => 'Advanced Queue', + ); + } + + function setUp() { + parent::setUp('advancedqueue'); + variable_set('queue_default_class', 'AdvancedQueue'); + } +} diff --git a/views/advancedqueue_handler_field_status.inc b/views/advancedqueue_handler_field_status.inc index 5b7af87..4765138 100644 --- a/views/advancedqueue_handler_field_status.inc +++ b/views/advancedqueue_handler_field_status.inc @@ -6,21 +6,22 @@ class advancedqueue_handler_field_status extends views_handler_field { function render($values) { $options = array( - -1 => t('Queued'), - 0 => t('Processing'), - 1 => t('Processed'), - 2 => t('Failed'), + ADVANCEDQUEUE_STATUS_QUEUED => t('Queued'), + ADVANCEDQUEUE_STATUS_PROCESSING => t('Processing'), + ADVANCEDQUEUE_STATUS_SUCCESS => t('Processed'), + ADVANCEDQUEUE_STATUS_FAILURE => t('Failed'), ); + $classes = array( - -1 => 'queued', - 0 => 'processing', - 1 => 'processed', - 2 => 'failed', + ADVANCEDQUEUE_STATUS_QUEUED => 'queued', + ADVANCEDQUEUE_STATUS_PROCESSING => 'processing', + ADVANCEDQUEUE_STATUS_SUCCESS => 'processed', + ADVANCEDQUEUE_STATUS_FAILURE => 'failed', ); $output = array( '#attached' => array( - 'css' => array(drupal_get_path('module', 'advancedqueue') . '/advancedqueue.css'), + 'css' => array(drupal_get_path('module', 'advancedqueue') . '/css/advancedqueue.css'), ), '#markup' => '' . $options[$values->{$this->field_alias}] . '', ); diff --git a/views/advancedqueue_handler_field_title.inc b/views/advancedqueue_handler_field_title.inc index 98b6446..8ad6d01 100644 --- a/views/advancedqueue_handler_field_title.inc +++ b/views/advancedqueue_handler_field_title.inc @@ -26,6 +26,6 @@ class advancedqueue_handler_field_title extends views_handler_field { '@item_uid' => $values->{$this->aliases['uid']}, ); - return t($values->{$this->field_alias}, $placeholders); + return format_string($values->{$this->field_alias}, $placeholders); } }