Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
Paweł Graczyk committed Feb 24, 2011
1 parent 2f78a00 commit 29304eb
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
8 changes: 7 additions & 1 deletion Entity/TaskBuffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ public function priority($priority)
return $this;
}

public function time($startTime, $endTime = null)
/**
* Sets window for task execution.
*
* @param \DateTime $startTime
* @param \DateTime $endTime
*/
public function time( \DateTime $startTime, \DateTime $endTime = null)
{
if (!$startTime instanceof \DateTime and !$endTime instanceof \DateTime)
{
Expand Down
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,42 @@ How to use

In the controller we have some action. In this action we queue static method and normal method call.

queue( callable [, group_identifier] ) - Store task in a buffer.

failuresLimit( int limit ) - Limit of tries for task execution.

priority( int priority ) - Tasks with lower number goes first.
time( DateTime $timeFrom, DateTime $timeUntil ) - Task execution occur only between specified hours.

public function someAction()
{
...

// load service
$taskBuffer = $this->get( 'task_buffer.task_buffer' );
// queue static method call
// Queue invocation of \Application\SomeBundle\Entity\SomeObject::someStaticMethod();
$taskBuffer->queue( '\Application\SomeBundle\Entity\SomeObject::someStaticMethod' );

// queue object method method call
// Queue invocation of $someObject->someMethod();
$someObject = new \Application\SomeBundle\Entity\SomeObject();
$taskBuffer->queue( array( $someObject, 'someMethod' ) );

// Queue invocation of $objectX->hello22().
// Invocation will be executed in 2 hours window. For example, if queue is executed at 11.31 the window is from 10.31 to 12.31 every day till successfull execution of the task,
// or untill failuresLimit is reached what gives 5 tries.
// Task will not be executed if there are any tasks with higher priority awaiting, 'higher' means number lower than 50 (0 goes first, 1000 last).

$timeFrom = new \DateTime(date('H:i:s'));
$timeUntil = new \DateTime(date('H:i:s'));

$taskBuffer->
failuresLimit(5)->
priority(50)->
time($timeFrom->modify('-1 houre'), $timeUntil->modify('+1 houre'))->
queue( array( $objectX, 'someMethodOk2' ), 'hello22' );

...
}

Expand Down

0 comments on commit 29304eb

Please sign in to comment.