Skip to content

diler-dev/mongo-queue

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Mongo-Queue

MongoQueue is a Kohana queue that allows for moving tasks and jobs into an asynchronous process for completion in the background. The queue is managed by MongoDB and MongoDb PHP ODM

This Kohana module is using code from https://github.com/lunaru/MongoQueue. TNX lunaru!

Requirements

Installation

Extract the source files into a modules directory in your Kohana installation.

Usage

class Controller_Queue extends Controller
{
  public function action_index()
	{
		Mongo_Queue::push('Queue_Task', 'trace', array(), time());
		
		if (Mongo_Queue::run())
			echo("Found a job to run");
		else
			echo("Nothing to run");
     
	}
}

Jobs are PHP objects that extend from Mongo_Job. Object states are not serialized so jobs must be defined as public static function.

class Queue_Task extends Mongo_Job
{
  public static $context;
  
	public static function trace()
	{
		echo "Tracer hit\n";
	}
}

You can also take advantage of @Mongo_Job@’s built in later() method which automatically delays a method for asynchronous running:

Queue_Tracer::later(500)->trace();

You can also batch calls which have the same parameter so that they’ll only be run once by workers. The run time will be decided by the first job inserted and the subsequent jobs will not have their run times obeyed.

Queue_Tracer::batchLater(500)->trace();

Running the jobs

Jobs are run via Mongo_Queue::run(). Mongo_Queue currently does not include a daemon runner (coming soon).

Administration

Indexing/Performance

You’ll want to add indices to Mongo_Queue to ensure high performance. You’ll need at least the following index for basic operation:

db.queue.ensureIndex({locked: 1, when: 1});

If you plan to use the batching feature you want an index on the type of jobs already in the queue:

 db.queue.ensureIndex({object_class: 1, object_method: 1, parameters: 1, locked: 1}); 

About

Kohana 3.2 queue module that uses mongodb

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages