mirror of
https://github.com/vichan-devel/vichan.git
synced 2025-01-31 12:23:48 +01:00
Allow queue push to fail gracefully
This commit is contained in:
parent
09dc44ec40
commit
f47332cdff
@ -2924,10 +2924,15 @@ function generation_strategy($fun, $array=array()) { global $config;
|
|||||||
_syslog(LOG_ERR, "Could not initialize generate queue, falling back to immediate rebuild strategy");
|
_syslog(LOG_ERR, "Could not initialize generate queue, falling back to immediate rebuild strategy");
|
||||||
}
|
}
|
||||||
return 'rebuild';
|
return 'rebuild';
|
||||||
} else {
|
|
||||||
$queue->push(serialize(array('build', $fun, $array, $action)));
|
|
||||||
return 'ignore';
|
|
||||||
}
|
}
|
||||||
|
$ret = $queue->push(serialize(array('build', $fun, $array, $action)));
|
||||||
|
if ($ret === false) {
|
||||||
|
if ($config['syslog']) {
|
||||||
|
_syslog(LOG_ERR, "Could not push item in the queue, falling back to immediate rebuild strategy");
|
||||||
|
}
|
||||||
|
return 'rebuild';
|
||||||
|
}
|
||||||
|
return 'ignore';
|
||||||
case 'build_on_load':
|
case 'build_on_load':
|
||||||
return 'delete';
|
return 'delete';
|
||||||
}
|
}
|
||||||
|
@ -22,11 +22,11 @@ class Queues {
|
|||||||
$this->key = $key;
|
$this->key = $key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function push(string $str): Queue {
|
public function push(string $str): bool {
|
||||||
$this->lock->get_ex();
|
$this->lock->get_ex();
|
||||||
file_put_contents($this->key . microtime(true), $str);
|
$ret = file_put_contents($this->key . microtime(true), $str);
|
||||||
$this->lock->free();
|
$this->lock->free();
|
||||||
return $this;
|
return $ret !== false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pop(int $n = 1): array {
|
public function pop(int $n = 1): array {
|
||||||
@ -63,8 +63,8 @@ class Queues {
|
|||||||
*/
|
*/
|
||||||
public static function none(): Queue {
|
public static function none(): Queue {
|
||||||
return new class() implements Queue {
|
return new class() implements Queue {
|
||||||
public function push(string $str): Queue {
|
public function push(string $str): bool {
|
||||||
return $this;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function pop(int $n = 1): array {
|
public function pop(int $n = 1): array {
|
||||||
@ -91,7 +91,7 @@ class Queues {
|
|||||||
|
|
||||||
interface Queue {
|
interface Queue {
|
||||||
// Push a string in the queue.
|
// Push a string in the queue.
|
||||||
public function push(string $str): Queue;
|
public function push(string $str): bool;
|
||||||
|
|
||||||
// Get a string from the queue.
|
// Get a string from the queue.
|
||||||
public function pop(int $n = 1): array;
|
public function pop(int $n = 1): array;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user