elefant/app-resque

PHP-Resque integration for the Elefant CMS

Installs: 8

Dependents: 0

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 1

Type:elefant-app

dev-master 2013-09-17 04:23 UTC

This package is auto-updated.

Last update: 2024-04-25 05:50:48 UTC


README

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