Insert task to Queue only if unique I wanted a way to only insert items into the Queue when it was not already added. I want to have a large queue and work my way through it, simply adding as required. Previously I was deleting the queue and recreating on a set time table.

I couldn't find any way of doing this, or any discussion other than 'it's not possible.

I created the method below. I have not used it for huge queues yet, but I post it here in the hope that better options if available might get posted too.
Create a class to extend the systemqueue. I called mine Unique. This will serialise the data use db_merge to insert only if it doesn't exist.

class Unique extends SystemQueue {

  public function createItem($data) {

    // save doing this twice
    $serial_data = serialize($data);

    // ignoring expire
    $query = db_merge('queue')
    -&gt;key(array('name' =&gt; $this-&gt;name, 'data' =&gt; $serial_data))
    -&gt;fields(array(
        'name' =&gt; $this-&gt;name,
        'data' =&gt; $serial_data,
        'created' =&gt; time(),
    ));
    return (bool) $query-&gt;execute();
  }
}


You then add the variables to hook_install() or hook_enable().

variable_set('queue_class_[your queue name]', 'Unique');


matching [your queue name] to the queue name, e.g if you used this:

DrupalQueue::get('update_profile_tasks')-&gt;createQueue();


the variable would be:

variable_set('queue_class_update_profile_tasks', 'Unique');


Thanks to this for getting me on track. Updated answer to be cleaner thanks to comment suggestions.