elefant/app-resque

PHP-Resque integration for the Elefant CMS


Keywords
queue, cms, cron, Tasks, app, elefant, resque, scheduler, workers, background tasks, task queue
License
MIT

Documentation

Resque app for Elefant

This is an app that integrates PHP-Resque into the Elefant CMS, so you can easily add background tasks to your apps.

Requirements

PHP-Resque requires Redis 2.2+ as well as the PCNTL extension.

Installation

  1. Install the app into the apps/ folder.
  2. Copy apps/resque/conf/config.php to conf/app.resque.config.php and edit the settings there.

Adding jobs to the queue

First you need to initialize the app for adding jobs to the queue:

<?php

// Initialize the Resque app
$this->run ('resque/init');

?>

After initializing the app, you can call Resque::enqueue() anywhere after that.

<?php

// Enqueue a job after calling resque/init
Resque::enqueue ('queue_name', 'JobName', array ('arg1' => 'value'));

?>

Defining jobs

Defining a job in Resque is done by creating a class named after the job name with a perform() method that will be called on to perform the job:

<?php

class JobName {
	public function perform () {
		printf ("Test job, received: %s\n", $this->args['arg1']);
	}
}

?>

Save this to your app's lib/ folder, e.g., apps/myapp/lib/JobName.php.

Running the workers

To start running the workers, use the following command:

$ ./elefant resque/run

You can also override most of the settings by passing parameters to the command, including:

  • --help Display help output
  • --logging=(off|normal|verbose) Set the logging level
  • --pid-file=./resque.pid Set the PID file
  • --queue=queue_name Specify the queue to watch
  • --sleep-interval=5 Seconds to sleep for
  • --workers=5 Number of workers to spawn