Version Notes
Fixed issue connecting to database using Unix sockets. Add option to execute job immediately and queue on failure.
Download this release
Release Info
| Developer | Jordan Owens |
| Extension | Jowens_JobQueue |
| Version | 0.2.0 |
| Comparing to | |
| See all releases | |
Code changes from version 0.1.0 to 0.2.0
- app/code/community/Jowens/JobQueue/Block/Adminhtml/Job/View.php +1 -2
- app/code/community/Jowens/JobQueue/Block/Adminhtml/Queue.php +0 -0
- app/code/community/Jowens/JobQueue/Block/Adminhtml/Queue/Grid.php +0 -0
- app/code/community/Jowens/JobQueue/Helper/Data.php +0 -0
- app/code/community/Jowens/JobQueue/Model/Job.php +0 -0
- app/code/community/Jowens/JobQueue/Model/Job/Abstract.php +19 -10
- app/code/community/Jowens/JobQueue/Model/Resource/Job.php +0 -0
- app/code/community/Jowens/JobQueue/Model/Resource/Job/Collection.php +0 -0
- app/code/community/Jowens/JobQueue/Model/Resource/Setup.php +0 -0
- app/code/community/Jowens/JobQueue/Model/Worker.php +10 -2
- app/code/community/Jowens/JobQueue/controllers/Adminhtml/QueueController.php +5 -5
- app/code/community/Jowens/JobQueue/etc/adminhtml.xml +0 -0
- app/code/community/Jowens/JobQueue/etc/config.xml +2 -2
- app/code/community/Jowens/JobQueue/etc/system.xml +0 -0
- app/code/community/Jowens/JobQueue/sql/jobqueue_setup/mysql4-install-0.1.0.php +0 -0
- app/design/adminhtml/default/default/layout/jowens/jobqueue.xml +0 -0
- app/design/adminhtml/default/default/template/jowens/jobqueue/job.phtml +0 -0
- app/etc/modules/Jowens_JobQueue.xml +0 -0
- lib/DJJob/DJJob.php +64 -22
- lib/DJJob/LICENSE +19 -0
- lib/DJJob/README.textile +0 -0
- lib/DJJob/composer.json +12 -0
- lib/DJJob/examples/HelloWorldJob.php +0 -0
- lib/DJJob/jobs.sql +0 -0
- lib/DJJob/test/database.php +26 -2
- package.xml +6 -6
app/code/community/Jowens/JobQueue/Block/Adminhtml/Job/View.php
CHANGED
|
@@ -70,6 +70,5 @@ class Jowens_JobQueue_Block_Adminhtml_Job_View extends Mage_Adminhtml_Block_Widg
|
|
| 70 |
: $this->__('N/A');
|
| 71 |
$this->setCreatedAtHtml($this->escapeHtml($createdAt));
|
| 72 |
return parent::_toHtml();
|
| 73 |
-
}
|
| 74 |
-
|
| 75 |
}
|
| 70 |
: $this->__('N/A');
|
| 71 |
$this->setCreatedAtHtml($this->escapeHtml($createdAt));
|
| 72 |
return parent::_toHtml();
|
| 73 |
+
}
|
|
|
|
| 74 |
}
|
app/code/community/Jowens/JobQueue/Block/Adminhtml/Queue.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Block/Adminhtml/Queue/Grid.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Helper/Data.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Model/Job.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Model/Job/Abstract.php
CHANGED
|
@@ -13,16 +13,25 @@ abstract class Jowens_JobQueue_Model_Job_Abstract extends Mage_Core_Model_Abstra
|
|
| 13 |
|
| 14 |
public abstract function perform();
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
$job->setRunAt($run_at);
|
| 23 |
-
$job->setCreatedAt(now());
|
| 24 |
-
$job->save();
|
| 25 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
public function setName($name)
|
| 28 |
{
|
|
@@ -50,4 +59,4 @@ abstract class Jowens_JobQueue_Model_Job_Abstract extends Mage_Core_Model_Abstra
|
|
| 50 |
{
|
| 51 |
return get_class($this);
|
| 52 |
}
|
| 53 |
-
}
|
| 13 |
|
| 14 |
public abstract function perform();
|
| 15 |
|
| 16 |
+
public function performImmediate($retryQueue="default") {
|
| 17 |
+
try {
|
| 18 |
+
$this->perform();
|
| 19 |
+
} catch(Exception $e) {
|
| 20 |
+
$this->enqueue($retryQueue);
|
| 21 |
+
Mage::log($e);
|
|
|
|
|
|
|
|
|
|
| 22 |
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
public function enqueue($queue="default", $run_at=null) {
|
| 26 |
+
$job = Mage::getModel('jobqueue/job');
|
| 27 |
+
$job->setStoreId($this->getStoreId());
|
| 28 |
+
$job->setName($this->getName());
|
| 29 |
+
$job->setHandler(serialize($this));
|
| 30 |
+
$job->setQueue($queue);
|
| 31 |
+
$job->setRunAt($run_at);
|
| 32 |
+
$job->setCreatedAt(now());
|
| 33 |
+
$job->save();
|
| 34 |
+
}
|
| 35 |
|
| 36 |
public function setName($name)
|
| 37 |
{
|
| 59 |
{
|
| 60 |
return get_class($this);
|
| 61 |
}
|
| 62 |
+
}
|
app/code/community/Jowens/JobQueue/Model/Resource/Job.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Model/Resource/Job/Collection.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Model/Resource/Setup.php
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/Model/Worker.php
CHANGED
|
@@ -79,9 +79,17 @@ class Jowens_JobQueue_Model_Worker extends Mage_Core_Model_Abstract
|
|
| 79 |
|
| 80 |
protected function setupDJJob() {
|
| 81 |
$config = Mage::getConfig()->getResourceConnectionConfig("default_setup");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
DJJob::configure(
|
| 83 |
-
|
| 84 |
array('mysql_user' => $config->username, 'mysql_pass' => $config->password)
|
| 85 |
);
|
| 86 |
-
}
|
| 87 |
}
|
| 79 |
|
| 80 |
protected function setupDJJob() {
|
| 81 |
$config = Mage::getConfig()->getResourceConnectionConfig("default_setup");
|
| 82 |
+
|
| 83 |
+
$dsn = "";
|
| 84 |
+
if (strpos($config->host, '/') !== false) {
|
| 85 |
+
$dsn = "mysql:unix_socket=" . $config->host . ";dbname=" . $config->dbname;
|
| 86 |
+
} else {
|
| 87 |
+
$dsn = "mysql:host=" . $config->host . ";dbname=" . $config->dbname . ";port=" . $config->port;
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
DJJob::configure(
|
| 91 |
+
$dsn,
|
| 92 |
array('mysql_user' => $config->username, 'mysql_pass' => $config->password)
|
| 93 |
);
|
| 94 |
+
}
|
| 95 |
}
|
app/code/community/Jowens/JobQueue/controllers/Adminhtml/QueueController.php
CHANGED
|
@@ -2,11 +2,11 @@
|
|
| 2 |
|
| 3 |
class Jowens_JobQueue_Adminhtml_QueueController extends Mage_Adminhtml_Controller_Action
|
| 4 |
{
|
| 5 |
-
|
| 6 |
{
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
|
| 11 |
protected function _init()
|
| 12 |
{
|
|
@@ -19,7 +19,7 @@ class Jowens_JobQueue_Adminhtml_QueueController extends Mage_Adminhtml_Controlle
|
|
| 19 |
return $this;
|
| 20 |
}
|
| 21 |
|
| 22 |
-
|
| 23 |
{
|
| 24 |
$id = $this->getRequest()->getParam('id');
|
| 25 |
$job = Mage::getModel('jobqueue/job');
|
| 2 |
|
| 3 |
class Jowens_JobQueue_Adminhtml_QueueController extends Mage_Adminhtml_Controller_Action
|
| 4 |
{
|
| 5 |
+
public function indexAction()
|
| 6 |
{
|
| 7 |
+
$this->_init()
|
| 8 |
+
->renderLayout();
|
| 9 |
+
}
|
| 10 |
|
| 11 |
protected function _init()
|
| 12 |
{
|
| 19 |
return $this;
|
| 20 |
}
|
| 21 |
|
| 22 |
+
public function viewAction()
|
| 23 |
{
|
| 24 |
$id = $this->getRequest()->getParam('id');
|
| 25 |
$job = Mage::getModel('jobqueue/job');
|
app/code/community/Jowens/JobQueue/etc/adminhtml.xml
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/etc/config.xml
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<Jowens_JobQueue>
|
| 5 |
-
<version>0.
|
| 6 |
</Jowens_JobQueue>
|
| 7 |
</modules>
|
| 8 |
<global>
|
|
@@ -92,4 +92,4 @@
|
|
| 92 |
</config>
|
| 93 |
</jobqueue>
|
| 94 |
</default>
|
| 95 |
-
</config>
|
| 2 |
<config>
|
| 3 |
<modules>
|
| 4 |
<Jowens_JobQueue>
|
| 5 |
+
<version>0.2.0</version>
|
| 6 |
</Jowens_JobQueue>
|
| 7 |
</modules>
|
| 8 |
<global>
|
| 92 |
</config>
|
| 93 |
</jobqueue>
|
| 94 |
</default>
|
| 95 |
+
</config>
|
app/code/community/Jowens/JobQueue/etc/system.xml
CHANGED
|
File without changes
|
app/code/community/Jowens/JobQueue/sql/jobqueue_setup/mysql4-install-0.1.0.php
CHANGED
|
File without changes
|
app/design/adminhtml/default/default/layout/jowens/jobqueue.xml
CHANGED
|
File without changes
|
app/design/adminhtml/default/default/template/jowens/jobqueue/job.phtml
CHANGED
|
File without changes
|
app/etc/modules/Jowens_JobQueue.xml
CHANGED
|
File without changes
|
lib/DJJob/DJJob.php
CHANGED
|
@@ -31,8 +31,9 @@ class DJBase {
|
|
| 31 |
|
| 32 |
private static $dsn = "";
|
| 33 |
private static $options = array(
|
| 34 |
-
"mysql_user"
|
| 35 |
-
"mysql_pass"
|
|
|
|
| 36 |
);
|
| 37 |
|
| 38 |
// use either `configure` or `setConnection`, depending on if
|
|
@@ -71,24 +72,60 @@ class DJBase {
|
|
| 71 |
}
|
| 72 |
|
| 73 |
public static function runQuery($sql, $params = array()) {
|
| 74 |
-
$
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
}
|
| 83 |
|
| 84 |
-
|
| 85 |
-
return $ret;
|
| 86 |
}
|
| 87 |
|
| 88 |
public static function runUpdate($sql, $params = array()) {
|
| 89 |
-
$
|
| 90 |
-
|
| 91 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
}
|
| 93 |
|
| 94 |
protected static function log($mesg, $severity=self::CRITICAL) {
|
|
@@ -220,8 +257,8 @@ class DJJob extends DJBase {
|
|
| 220 |
# pull the handler from the db
|
| 221 |
$handler = $this->getHandler();
|
| 222 |
if (!is_object($handler)) {
|
| 223 |
-
$
|
| 224 |
-
$this->finishWithError(
|
| 225 |
return false;
|
| 226 |
}
|
| 227 |
|
|
@@ -240,8 +277,8 @@ class DJJob extends DJBase {
|
|
| 240 |
$msg = "Caught DJRetryException \"{$e->getMessage()}\" on attempt $attempts/{$this->max_attempts}.";
|
| 241 |
|
| 242 |
if($attempts == $this->max_attempts) {
|
| 243 |
-
$
|
| 244 |
-
$this->finishWithError($msg);
|
| 245 |
} else {
|
| 246 |
$this->log("[JOB] job::{$this->job_id} $msg Try again in {$e->getDelay()} seconds.", self::WARN);
|
| 247 |
$this->retryLater($e->getDelay());
|
|
@@ -250,7 +287,7 @@ class DJJob extends DJBase {
|
|
| 250 |
|
| 251 |
} catch (Exception $e) {
|
| 252 |
|
| 253 |
-
$this->finishWithError($e->getMessage());
|
| 254 |
return false;
|
| 255 |
|
| 256 |
}
|
|
@@ -290,7 +327,7 @@ class DJJob extends DJBase {
|
|
| 290 |
$this->log("[JOB] completed job::{$this->job_id}", self::INFO);
|
| 291 |
}
|
| 292 |
|
| 293 |
-
public function finishWithError($error) {
|
| 294 |
$this->runUpdate("
|
| 295 |
UPDATE jobs
|
| 296 |
SET attempts = attempts + 1,
|
|
@@ -304,8 +341,13 @@ class DJJob extends DJBase {
|
|
| 304 |
$this->job_id
|
| 305 |
)
|
| 306 |
);
|
|
|
|
| 307 |
$this->log("[JOB] failure in job::{$this->job_id}", self::ERROR);
|
| 308 |
$this->releaseLock();
|
|
|
|
|
|
|
|
|
|
|
|
|
| 309 |
}
|
| 310 |
|
| 311 |
public function retryLater($delay) {
|
|
@@ -351,7 +393,7 @@ class DJJob extends DJBase {
|
|
| 351 |
return false;
|
| 352 |
}
|
| 353 |
|
| 354 |
-
return
|
| 355 |
}
|
| 356 |
|
| 357 |
public static function bulkEnqueue($handlers, $queue = "default", $run_at = null) {
|
| 31 |
|
| 32 |
private static $dsn = "";
|
| 33 |
private static $options = array(
|
| 34 |
+
"mysql_user" => null,
|
| 35 |
+
"mysql_pass" => null,
|
| 36 |
+
"mysql_retries" => 3
|
| 37 |
);
|
| 38 |
|
| 39 |
// use either `configure` or `setConnection`, depending on if
|
| 72 |
}
|
| 73 |
|
| 74 |
public static function runQuery($sql, $params = array()) {
|
| 75 |
+
$retries = self::$options["mysql_retries"];
|
| 76 |
+
|
| 77 |
+
for ($attempts = 0; $attempts < $retries; $attempts++) {
|
| 78 |
+
try {
|
| 79 |
+
$stmt = self::getConnection()->prepare($sql);
|
| 80 |
+
$stmt->execute($params);
|
| 81 |
+
|
| 82 |
+
$ret = array();
|
| 83 |
+
if ($stmt->rowCount()) {
|
| 84 |
+
// calling fetchAll on a result set with no rows throws a
|
| 85 |
+
// "general error" exception
|
| 86 |
+
foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $r) $ret []= $r;
|
| 87 |
+
}
|
| 88 |
+
|
| 89 |
+
$stmt->closeCursor();
|
| 90 |
+
return $ret;
|
| 91 |
+
}
|
| 92 |
+
catch (PDOException $e) {
|
| 93 |
+
// Catch "MySQL server has gone away" error.
|
| 94 |
+
if ($e->errorInfo[1] == 2006) {
|
| 95 |
+
self::$db = null;
|
| 96 |
+
}
|
| 97 |
+
// Throw all other errors as expected.
|
| 98 |
+
else {
|
| 99 |
+
throw $e;
|
| 100 |
+
}
|
| 101 |
+
}
|
| 102 |
}
|
| 103 |
|
| 104 |
+
throw new DJException("DJJob exhausted retries connecting to database");
|
|
|
|
| 105 |
}
|
| 106 |
|
| 107 |
public static function runUpdate($sql, $params = array()) {
|
| 108 |
+
$retries = self::$options["mysql_retries"];
|
| 109 |
+
|
| 110 |
+
for ($attempts = 0; $attempts < $retries; $attempts++) {
|
| 111 |
+
try {
|
| 112 |
+
$stmt = self::getConnection()->prepare($sql);
|
| 113 |
+
$stmt->execute($params);
|
| 114 |
+
return $stmt->rowCount();
|
| 115 |
+
}
|
| 116 |
+
catch (PDOException $e) {
|
| 117 |
+
// Catch "MySQL server has gone away" error.
|
| 118 |
+
if ($e->errorInfo[1] == 2006) {
|
| 119 |
+
self::$db = null;
|
| 120 |
+
}
|
| 121 |
+
// Throw all other errors as expected.
|
| 122 |
+
else {
|
| 123 |
+
throw $e;
|
| 124 |
+
}
|
| 125 |
+
}
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
throw new DJException("DJJob exhausted retries connecting to database");
|
| 129 |
}
|
| 130 |
|
| 131 |
protected static function log($mesg, $severity=self::CRITICAL) {
|
| 257 |
# pull the handler from the db
|
| 258 |
$handler = $this->getHandler();
|
| 259 |
if (!is_object($handler)) {
|
| 260 |
+
$msg = "[JOB] bad handler for job::{$this->job_id}";
|
| 261 |
+
$this->finishWithError($msg);
|
| 262 |
return false;
|
| 263 |
}
|
| 264 |
|
| 277 |
$msg = "Caught DJRetryException \"{$e->getMessage()}\" on attempt $attempts/{$this->max_attempts}.";
|
| 278 |
|
| 279 |
if($attempts == $this->max_attempts) {
|
| 280 |
+
$msg = "[JOB] job::{$this->job_id} $msg Giving up.";
|
| 281 |
+
$this->finishWithError($msg, $handler);
|
| 282 |
} else {
|
| 283 |
$this->log("[JOB] job::{$this->job_id} $msg Try again in {$e->getDelay()} seconds.", self::WARN);
|
| 284 |
$this->retryLater($e->getDelay());
|
| 287 |
|
| 288 |
} catch (Exception $e) {
|
| 289 |
|
| 290 |
+
$this->finishWithError($e->getMessage(), $handler);
|
| 291 |
return false;
|
| 292 |
|
| 293 |
}
|
| 327 |
$this->log("[JOB] completed job::{$this->job_id}", self::INFO);
|
| 328 |
}
|
| 329 |
|
| 330 |
+
public function finishWithError($error, $handler = null) {
|
| 331 |
$this->runUpdate("
|
| 332 |
UPDATE jobs
|
| 333 |
SET attempts = attempts + 1,
|
| 341 |
$this->job_id
|
| 342 |
)
|
| 343 |
);
|
| 344 |
+
$this->log($error, self::ERROR);
|
| 345 |
$this->log("[JOB] failure in job::{$this->job_id}", self::ERROR);
|
| 346 |
$this->releaseLock();
|
| 347 |
+
|
| 348 |
+
if ($handler && ($this->getAttempts() == $this->max_attempts) && method_exists($handler, '_onDjjobRetryError')) {
|
| 349 |
+
$handler->_onDjjobRetryError($error);
|
| 350 |
+
}
|
| 351 |
}
|
| 352 |
|
| 353 |
public function retryLater($delay) {
|
| 393 |
return false;
|
| 394 |
}
|
| 395 |
|
| 396 |
+
return self::getConnection()->lastInsertId(); // return the job ID, for manipulation later
|
| 397 |
}
|
| 398 |
|
| 399 |
public static function bulkEnqueue($handlers, $queue = "default", $run_at = null) {
|
lib/DJJob/LICENSE
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright (c) 2013 SeatGeek, Inc.
|
| 2 |
+
|
| 3 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 4 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 5 |
+
in the Software without restriction, including without limitation the rights
|
| 6 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 7 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 8 |
+
furnished to do so, subject to the following conditions:
|
| 9 |
+
|
| 10 |
+
The above copyright notice and this permission notice shall be included in
|
| 11 |
+
all copies or substantial portions of the Software.
|
| 12 |
+
|
| 13 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 14 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 15 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 16 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 17 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 18 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
| 19 |
+
THE SOFTWARE.
|
lib/DJJob/README.textile
CHANGED
|
File without changes
|
lib/DJJob/composer.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"name": "seatgeek/djjob",
|
| 3 |
+
"type": "library",
|
| 4 |
+
"description": "Allows PHP web applications to process long-running tasks asynchronously",
|
| 5 |
+
"keywords": ["PHP","asynchronous", "task","job"],
|
| 6 |
+
"require": {
|
| 7 |
+
"php": ">=5.1.0"
|
| 8 |
+
},
|
| 9 |
+
"autoload": {
|
| 10 |
+
"psr-0": { "DJJob": "" }
|
| 11 |
+
}
|
| 12 |
+
}
|
lib/DJJob/examples/HelloWorldJob.php
CHANGED
|
File without changes
|
lib/DJJob/jobs.sql
CHANGED
|
File without changes
|
lib/DJJob/test/database.php
CHANGED
|
@@ -1,5 +1,14 @@
|
|
| 1 |
<?php
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
date_default_timezone_set('America/New_York');
|
| 4 |
|
| 5 |
require dirname(__FILE__) . "/../DJJob.php";
|
|
@@ -42,7 +51,14 @@ class FailingJob {
|
|
| 42 |
}
|
| 43 |
}
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
DJJob::enqueue(new HelloWorldJob("delayed_job"));
|
| 48 |
DJJob::bulkEnqueue(array(
|
|
@@ -50,8 +66,16 @@ DJJob::bulkEnqueue(array(
|
|
| 50 |
new HelloWorldJob("github"),
|
| 51 |
));
|
| 52 |
DJJob::enqueue(new FailingJob());
|
|
|
|
|
|
|
| 53 |
|
| 54 |
$worker = new DJWorker(array("count" => 5, "max_attempts" => 2, "sleep" => 10));
|
| 55 |
$worker->start();
|
|
|
|
|
|
|
|
|
|
| 56 |
|
| 57 |
-
|
|
|
|
|
|
|
|
|
| 1 |
<?php
|
| 2 |
|
| 3 |
+
function assert_handler($file, $line, $code, $desc = null) {
|
| 4 |
+
printf("Assertion failed at %s:%s: %s: %s\n", $file, $line, $code, $desc);
|
| 5 |
+
}
|
| 6 |
+
|
| 7 |
+
assert_options(ASSERT_ACTIVE, 1);
|
| 8 |
+
assert_options(ASSERT_WARNING, 0);
|
| 9 |
+
assert_options(ASSERT_QUIET_EVAL, 1);
|
| 10 |
+
assert_options(ASSERT_CALLBACK, 'assert_handler');
|
| 11 |
+
|
| 12 |
date_default_timezone_set('America/New_York');
|
| 13 |
|
| 14 |
require dirname(__FILE__) . "/../DJJob.php";
|
| 51 |
}
|
| 52 |
}
|
| 53 |
|
| 54 |
+
$status = DJJob::status();
|
| 55 |
+
|
| 56 |
+
assert('$status["outstanding"] == 0', "Initial outstanding status is incorrect");
|
| 57 |
+
assert('$status["locked"] == 0', "Initial locked status is incorrect");
|
| 58 |
+
assert('$status["failed"] == 0', "Initial failed status is incorrect");
|
| 59 |
+
assert('$status["total"] == 0', "Initial total status is incorrect");
|
| 60 |
+
|
| 61 |
+
printf("=====================\nStarting run of DJJob\n=====================\n\n");
|
| 62 |
|
| 63 |
DJJob::enqueue(new HelloWorldJob("delayed_job"));
|
| 64 |
DJJob::bulkEnqueue(array(
|
| 66 |
new HelloWorldJob("github"),
|
| 67 |
));
|
| 68 |
DJJob::enqueue(new FailingJob());
|
| 69 |
+
// Test unicode support using the classic, rails snowman: http://www.fileformat.info/info/unicode/char/2603/browsertest.htm
|
| 70 |
+
DJJob::enqueue(new HelloWorldJob(html_entity_decode("☃", ENT_HTML5, "UTF-8")));
|
| 71 |
|
| 72 |
$worker = new DJWorker(array("count" => 5, "max_attempts" => 2, "sleep" => 10));
|
| 73 |
$worker->start();
|
| 74 |
+
printf("\n============\nRun complete\n============\n\n");
|
| 75 |
+
|
| 76 |
+
$status = DJJob::status();
|
| 77 |
|
| 78 |
+
assert('$status["outstanding"] == 0', "Final outstanding status is incorrect");
|
| 79 |
+
assert('$status["locked"] == 0', "Final locked status is incorrect");
|
| 80 |
+
assert('$status["failed"] == 1', "Final failed status is incorrect");
|
| 81 |
+
assert('$status["total"] == 1', "Final total status is incorrect");
|
package.xml
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Jowens_JobQueue</name>
|
| 4 |
-
<version>0.
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/MIT">MIT</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Asynchronous job queue for Magento</summary>
|
| 10 |
<description>JobQueue allows jobs to be queued in the database to be processed asynchronously.</description>
|
| 11 |
-
<notes>
|
| 12 |
<authors><author><name>Jordan Owens</name><user>jkowens</user><email>jkowens@gmail.com</email></author></authors>
|
| 13 |
-
<date>
|
| 14 |
-
<time>
|
| 15 |
-
<contents><target name="magecommunity"><dir name="Jowens"><dir name="JobQueue"><dir name="Block"><dir name="Adminhtml"><dir name="Job"><file name="View.php" hash="
|
| 16 |
<compatible/>
|
| 17 |
-
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php></required></dependencies>
|
| 18 |
</package>
|
| 1 |
<?xml version="1.0"?>
|
| 2 |
<package>
|
| 3 |
<name>Jowens_JobQueue</name>
|
| 4 |
+
<version>0.2.0</version>
|
| 5 |
<stability>stable</stability>
|
| 6 |
<license uri="http://opensource.org/licenses/MIT">MIT</license>
|
| 7 |
<channel>community</channel>
|
| 8 |
<extends/>
|
| 9 |
<summary>Asynchronous job queue for Magento</summary>
|
| 10 |
<description>JobQueue allows jobs to be queued in the database to be processed asynchronously.</description>
|
| 11 |
+
<notes>Fixed issue connecting to database using Unix sockets. Add option to execute job immediately and queue on failure.</notes>
|
| 12 |
<authors><author><name>Jordan Owens</name><user>jkowens</user><email>jkowens@gmail.com</email></author></authors>
|
| 13 |
+
<date>2014-01-07</date>
|
| 14 |
+
<time>19:38:00</time>
|
| 15 |
+
<contents><target name="magecommunity"><dir name="Jowens"><dir name="JobQueue"><dir name="Block"><dir name="Adminhtml"><dir name="Job"><file name="View.php" hash="c8fbae78ea626fa7273947245e77be3d"/></dir><dir name="Queue"><file name="Grid.php" hash="9618ecc67272f750c88e7e19680aaa44"/></dir><file name="Queue.php" hash="719a95c4bde9c4c109b159d0667de2da"/></dir></dir><dir name="Helper"><file name="Data.php" hash="8c8b3a2b79a1546e8b6600dde974c049"/></dir><dir name="Model"><dir name="Job"><file name="Abstract.php" hash="464af3c758f6c94fc768f48379bf287e"/></dir><file name="Job.php" hash="f0b9928c1063dc3d90087fb69de16fa4"/><dir name="Resource"><dir name="Job"><file name="Collection.php" hash="a175198f2c3d252dadb817d108920b3f"/></dir><file name="Job.php" hash="30843d577f463d43ed4e3807187e8248"/><file name="Setup.php" hash="911413029124da3964d9822926fb44de"/></dir><file name="Worker.php" hash="dfed14779daf2a060db649ccddd9c810"/></dir><dir name="controllers"><dir name="Adminhtml"><file name="QueueController.php" hash="a05f9d0828a7a18b27c1b966042e415f"/></dir></dir><dir name="etc"><file name="adminhtml.xml" hash="885171a59394683e2a8ec1d5701c0817"/><file name="config.xml" hash="826804a99f7ee2ce96aaabbdc87df3cb"/><file name="system.xml" hash="3a8426d2f3c9a3f29d4adff6733d3ea9"/></dir><dir name="sql"><dir name="jobqueue_setup"><file name="mysql4-install-0.1.0.php" hash="19592c4c921f2e1c64e85c1a776edda2"/></dir></dir></dir></dir></target><target name="mageetc"><dir name="modules"><file name="Jowens_JobQueue.xml" hash="272f42382ccc1b0226c7e25c078d54ae"/></dir></target><target name="magelib"><dir name="DJJob"><file name="DJJob.php" hash="c2a742d0e2cb43208844636b243ec8ae"/><file name="LICENSE" hash="34cf8e3fef5d267eb53ad593d4e14dd3"/><file name="README.textile" hash="ae3feeccf3476b207a05894aabf4afaf"/><file name="composer.json" hash="101e6cb50439389d03c73b7a5179dc0a"/><dir name="examples"><file name="HelloWorldJob.php" hash="3b7a9e4b1f912fb48acf5399f5fe33b9"/></dir><file name="jobs.sql" hash="d73a8213feedadf9dc9eb719fe33b935"/><dir name="test"><file name="database.php" hash="c130f97354004a05752ec114e9d2c9eb"/></dir><file name=".git" hash="6efe08f8b224dddac89f9229e7ccd042"/></dir></target><target name="magedesign"><dir name="adminhtml"><dir name="default"><dir name="default"><dir name="layout"><dir name="jowens"><file name="jobqueue.xml" hash="491d99d8da67cc879386dda4ef90f285"/></dir></dir><dir name="template"><dir name="jowens"><dir name="jobqueue"><file name="job.phtml" hash="1511cf6f2b85b62f77d6ce741004875e"/></dir></dir></dir></dir></dir></dir></target></contents>
|
| 16 |
<compatible/>
|
| 17 |
+
<dependencies><required><php><min>5.1.0</min><max>6.0.0</max></php><package><name>Mage_Core_Modules</name><channel>community</channel><min>1.6.0</min><max></max></package></required></dependencies>
|
| 18 |
</package>
|
