glorpen/queue-bundle

Task queue

Installs: 1 818

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 1

Open Issues: 0

Type:symfony-bundle

v0.3.3 2015-05-08 05:38 UTC

This package is not auto-updated.

Last update: 2024-05-11 13:26:05 UTC


README

Note: the repository is not maintained anymore.

Bundle for offloading work to server side. Can add service tasks/jobs to queue for later execution.

Queue runs can safely overlap since tasks are locked upon acquiring by runner.

For forking and other funnies:

Installation

  • add requirements to composer.json:

json

{
"require": {

"glorpen/queue-bundle": "*"

}

}

  • enable the bundle in your AppKernel class

app/AppKernel.php

php

<?php

class AppKernel extends AppKernel { public function registerBundles() { $bundles = array( ... new GlorpenQueueBundleGlorpenQueueBundle(), ... ); } }

  • choose backend in config.yml

Backends

Propel

Bundle configuration:

yaml

glorpen_queue:

backend: propel

Usage

To add new task:

php

<?php $queue = $container->get("glorpen.queue"); $queue->create('my.tasks_container', 'myMethod', array("arg1", 2));

Then to execute use app/console queue:run:

Starting task test:method Task 1:test:method ended after 0 seconds with status "failed"

Remember that:

  • dataset is fetched on task execution, so it can change after you create task.
  • task arguments are serialized and stored in choosen backend

Other useful commands:

  • queue:restart-failed simply marks failed tasks as pending
  • queue:update marks crashed (eg. on OOM) tasks as failed and removes succesfull tasks

Named tasks

To add new named task:

php

<?php $queue = $container->get("glorpen.queue"); $queue->create('my.tasks_container', 'myMethod', array("arg1", 2), 'now', 'my_named_task');

Then you can retrieve it with:

php

<?php $queue = $container->get("glorpen.queue"); $task = $queue->getTask('my_named_task'); echo $task->getStatus(); echo $task->getProgress();

When creating named task:

  • completed or not started task with same name will be removed
  • if old task is currently running an exception will be thrown

Metadata

Inside executing task you can set its current progress:

php

<?php $queue = $container->get("glorpen.queue"); $queue->setCurrentTaskProgress(50);