Last active
November 17, 2015 06:51
-
-
Save daum/9259785 to your computer and use it in GitHub Desktop.
Gearman worker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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