1. Go to this page and download the library: Download elvetemedve/djjob library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
// Job class
class HelloWorldJob {
public function __construct($name) {
$this->name = $name;
}
public function perform() {
echo "Hello {$this->name}!\n";
}
}
// enqueue a new job
DJJob::enqueue(new HelloWorldJob("delayed_job"));
class Email {
public function __construct($recipient) {
$this->recipient = $recipient;
}
public function send() {
// do some expensive work to build the email: geolocation, etc..
// use mail api to send this email
}
public function perform() {
$this->send();
}
public function sendLater() {
DJJob::enqueue($this, "email");
}
}
$worker = new DJWorker($options);
$worker->start();
class jobsWorkerTask extends sfPropelBaseTask {
protected function configure() {
$this->namespace = 'jobs';
$this->name = 'worker';
$this->briefDescription = '';
$this->detailedDescription = <<<EOF
The [jobs:worker|INFO] task runs jobs created by the DJJob system.
Call it with:
[php symfony jobs:worker|INFO]
EOF;
$this->addArgument('application', sfCommandArgument::OPTIONAL, 'The application name', 'customer');
$this->addOption('env', null, sfCommandOption::PARAMETER_REQUIRED, 'The environment', 'dev');
$this->addOption('connection', null, sfCommandOption::PARAMETER_REQUIRED, 'The connection name', 'propel');
$this->addOption('queue', null, sfCommandOption::PARAMETER_REQUIRED, 'The queue to pull jobs from', 'default');
$this->addOption('count', null, sfCommandOption::PARAMETER_REQUIRED, 'The number of jobs to run before exiting (0 for unlimited)', 0);
$this->addOption('sleep', null, sfCommandOption::PARAMETER_REQUIRED, 'Seconds to sleep after finding no new jobs', 5);
}
protected function execute($arguments = array(), $options = array()) {
// Database initialization
$databaseManager = new sfDatabaseManager($this->configuration);
$connection = Propel::getConnection($options['connection'] ? $options['connection'] : '');
$worker = new DJWorker($options);
$worker->start();
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.