Skip to content

Instantly share code, notes, and snippets.

@daum
Last active November 17, 2015 06:51
Show Gist options
  • Save daum/9259785 to your computer and use it in GitHub Desktop.
Save daum/9259785 to your computer and use it in GitHub Desktop.
Gearman worker
<?php
<?php
namespace My\DemoBundle\Gearman\Worker;
use Mmoreram\GearmanBundle\Driver\Gearman;
use Symfony\Component\DependencyInjection\Container;
/**
* @Gearman\Work(
* iterations = 30,
* description = "Test worker",
* service = "my.test_worker"
* )
*/
class TestWorker
{
private $container;
public function __construct(Container $container)
{
$this->container = $container;
}
/**
* Test method to run as a job
*
* @param \GearmanJob $job Object with job parameters
*
* @return boolean
*
* @Gearman\Job(
* name = "sendNotificationsToUsers",
* description = "Sends a list users an awesome notification"
* )
*/
public function sendNotificationsToUsers(\GearmanJob $job)
{
// Get the data we put in for the job previously.
$data = json_decode($job->workload(),true);
foreach($data['user_ids'] as $userId)
{
// Some task that takes a long, long time to do.
$notification->send();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment