Skip to content

Commit

Permalink
Add a new MongoJob class that other classes can derive from in order …
Browse files Browse the repository at this point in the history
…to get some syntactic sugar around inserting jobs
  • Loading branch information
lunaru committed Jul 24, 2010
1 parent 1a974f0 commit 4958788
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
20 changes: 20 additions & 0 deletions lib/MongoFunctor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

require_once('MongoQueue.php');

class MongoFunctor
{
protected $delay = 0;
protected $className = null;

public function __construct($className, $delay)
{
$this->className = $className;
$this->delay = $delay;
}
public function __call($method, $args)
{
MongoQueue::push($this->className, $method, $args, time() + $this->delay);
}
}

13 changes: 13 additions & 0 deletions lib/MongoJob.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

require_once('MongoQueue.php');
require_once('MongoFunctor.php');

abstract class MongoJob
{
public static function later($delay = 0)
{
$className = get_called_class();
return new MongoFunctor($className, $delay);
}
}
4 changes: 2 additions & 2 deletions lib/MongoQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ abstract class MongoQueue
public static $connection = null;
public static $collectionName = 'mongo_queue';

public static function push($className, $parameters, $when)
public static function push($className, $methodName, $parameters, $when)
{
$collection = self::getCollection();
$collection->save(array('object_class' => $className, 'parameters' => $parameters, 'when' => $when));
$collection->save(array('object_class' => $className, 'object_method' => $methodName, 'parameters' => $parameters, 'when' => $when));
}

public static function run()
Expand Down

0 comments on commit 4958788

Please sign in to comment.