Ejegg has submitted this change and it was merged.
Change subject: Interpret Predis status codes
......................................................................
Interpret Predis status codes
Response types vary by command. Take care to convert the meaning of each type
to the correct trueish value, for example "ERR" usually means we should return
false, or at times 0 could be a successful result.
Bug: T109527
Change-Id: Ic669a7259b5eae03f3c366e812b0039325363678
---
M src/PHPQueue/Backend/Predis.php
1 file changed, 14 insertions(+), 8 deletions(-)
Approvals:
Ejegg: Verified; Looks good to me, approved
diff --git a/src/PHPQueue/Backend/Predis.php b/src/PHPQueue/Backend/Predis.php
index 4a46948..fbe8e0f 100644
--- a/src/PHPQueue/Backend/Predis.php
+++ b/src/PHPQueue/Backend/Predis.php
@@ -1,6 +1,7 @@
<?php
namespace PHPQueue\Backend;
+use Predis\Response\ResponseInterface;
use Predis\Transaction\MultiExec;
use PHPQueue\Exception\BackendException;
@@ -103,8 +104,8 @@
throw new BackendException("Cannot push to indexed fifo queue
without correlation data.");
}
$status = $this->addToIndexedFifoQueue($key, $data);
- if (!$status) {
- throw new BackendException("Couldn't push to indexed fifo
queue.");
+ if (!self::boolStatus($status)) {
+ throw new BackendException('Couldn\'t push to indexed fifo
queue: ' . $status->getMessage());
}
} else {
// Note that we're ignoring the "new length" return value, cos I
don't
@@ -255,8 +256,8 @@
}
$job_data = $this->open_items[$jobId];
$status = $this->getConnection()->rpush($this->queue_name, $job_data);
- if (!$status) {
- throw new BackendException("Unable to save data.");
+ if (!is_int($status)) {
+ throw new BackendException('Unable to save data: ' .
$status->getMessage());
}
$this->last_job_id = $jobId;
$this->afterClearRelease();
@@ -298,8 +299,8 @@
$status = $this->getConnection()->set($key, $data);
}
}
- if (!$status) {
- throw new BackendException("Unable to save data.");
+ if (!self::boolStatus($status)) {
+ throw new BackendException('Unable to save data.: ' .
$status->getMessage());
}
} catch (\Exception $ex) {
throw new BackendException($ex->getMessage(), $ex->getCode());
@@ -311,6 +312,7 @@
*
* @param string $key
* @param array $data
+ * @return Predis\Response\ResponseInterface
*/
protected function addToIndexedFifoQueue($key, $data)
{
@@ -422,7 +424,7 @@
$status = $this->getConnection()->incrby($key, $count);
}
- return $status;
+ return is_int($status);
}
public function decrKey($key, $count=1)
@@ -436,7 +438,7 @@
$status = $this->getConnection()->decrby($key, $count);
}
- return $status;
+ return is_int($status);
}
public function keyExists($key)
@@ -449,4 +451,8 @@
{
return !empty($this->queue_name);
}
+
+ protected static function boolStatus(ResponseInterface $status) {
+ return ($status == 'OK' || $status == 'QUEUED');
+ }
}
--
To view, visit https://gerrit.wikimedia.org/r/232885
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Ic669a7259b5eae03f3c366e812b0039325363678
Gerrit-PatchSet: 3
Gerrit-Project: wikimedia/fundraising/php-queue
Gerrit-Branch: master
Gerrit-Owner: Awight <[email protected]>
Gerrit-Reviewer: AndyRussG <[email protected]>
Gerrit-Reviewer: Awight <[email protected]>
Gerrit-Reviewer: Cdentinger <[email protected]>
Gerrit-Reviewer: Ejegg <[email protected]>
Gerrit-Reviewer: Katie Horn <[email protected]>
Gerrit-Reviewer: XenoRyet <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits