mirror of
https://github.com/humhub/humhub.git
synced 2025-01-17 14:18:27 +01:00
Enh: Upgraded zhuravljov\yii\queue to version 0.11, fixed download issue
This commit is contained in:
parent
e30ae11a3e
commit
ac3ef62056
@ -28,7 +28,7 @@
|
||||
"nqxcode/zendsearch": "^2.0",
|
||||
"xj/yii2-jplayer-widget": "*",
|
||||
"zendframework/zend-ldap": "^2.5",
|
||||
"zhuravljov/yii2-queue": "^0.7",
|
||||
"zhuravljov/yii2-queue": "^0.11",
|
||||
"bower-asset/jquery-timeago": "1.4.*",
|
||||
"bower-asset/jquery-nicescroll": "3.6.*",
|
||||
"bower-asset/jquery-knob": "1.2.*",
|
||||
|
@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @link https://www.humhub.org/
|
||||
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
|
||||
* @license https://www.humhub.com/licences
|
||||
*/
|
||||
|
||||
namespace humhub\components\queue;
|
||||
|
||||
use Yii;
|
||||
use yii\base\Event;
|
||||
use zhuravljov\yii\queue\Queue as BaseQueue;
|
||||
use zhuravljov\yii\queue\ErrorEvent;
|
||||
|
||||
/**
|
||||
* Queue
|
||||
*
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class Queue extends BaseQueue
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
Event::on(Queue::class, Queue::EVENT_AFTER_ERROR, function(ErrorEvent $errorEvent) {
|
||||
/* @var $exception \Expection */
|
||||
$exception = $errorEvent->error;
|
||||
Yii::error('Could not execute queued job! Message: ' . $exception->getMessage() . ' Trace:' . $exception->getTraceAsString(), 'queue');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
@ -8,7 +8,10 @@
|
||||
|
||||
namespace humhub\components\queue\driver;
|
||||
|
||||
use zhuravljov\yii\queue\sync\Driver;
|
||||
use Yii;
|
||||
use yii\base\Event;
|
||||
use zhuravljov\yii\queue\ErrorEvent;
|
||||
use humhub\components\queue\Queue;
|
||||
|
||||
/**
|
||||
* Instant queue driver, mainly used for testing purposes
|
||||
@ -16,30 +19,29 @@ use zhuravljov\yii\queue\sync\Driver;
|
||||
* @since 1.2
|
||||
* @author buddha
|
||||
*/
|
||||
class Instant extends Driver
|
||||
class Instant extends Queue
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $handle = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $_messages = [];
|
||||
|
||||
/**
|
||||
* Executes the jobs immediatly, serialization is done for testing purpose
|
||||
*/
|
||||
public function push($job)
|
||||
public function init()
|
||||
{
|
||||
$this->_messages[] = $this->serialize($job);
|
||||
parent::init();
|
||||
|
||||
while (($message = array_shift($this->_messages)) !== null) {
|
||||
$job = $this->unserialize($message);
|
||||
$this->getQueue()->run($job);
|
||||
Event::on(Queue::class, Queue::EVENT_AFTER_ERROR, function(ErrorEvent $errorEvent) {
|
||||
/* @var $exception \Expection */
|
||||
$exception = $errorEvent->error;
|
||||
Yii::error('Could not execute queued job! Message: ' . $exception->getMessage() . ' Trace:' . $exception->getTraceAsString(), 'queue');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function sendMessage($message, $timeout)
|
||||
{
|
||||
$this->handleMessage($message);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,10 @@
|
||||
|
||||
namespace humhub\components\queue\driver;
|
||||
|
||||
use zhuravljov\yii\queue\db\Driver;
|
||||
use Yii;
|
||||
use yii\base\Event;
|
||||
use zhuravljov\yii\queue\ErrorEvent;
|
||||
use zhuravljov\yii\queue\db\Queue;
|
||||
|
||||
/**
|
||||
* MySQL queue driver
|
||||
@ -16,9 +19,26 @@ use zhuravljov\yii\queue\db\Driver;
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class MySQL extends Driver
|
||||
class MySQL extends Queue
|
||||
{
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public $mutex = 'yii\mutex\MysqlMutex';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
parent::init();
|
||||
|
||||
Event::on(Queue::class, Queue::EVENT_AFTER_ERROR, function(ErrorEvent $errorEvent) {
|
||||
/* @var $exception \Expection */
|
||||
$exception = $errorEvent->error;
|
||||
Yii::error('Could not execute queued job! Message: ' . $exception->getMessage() . ' Trace:' . $exception->getTraceAsString(), 'queue');
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,7 +8,12 @@
|
||||
|
||||
namespace humhub\components\queue\driver;
|
||||
|
||||
use zhuravljov\yii\queue\sync\Driver;
|
||||
use Yii;
|
||||
use yii\base\Event;
|
||||
use yii\base\Application;
|
||||
use yii\base\NotSupportedException;
|
||||
use zhuravljov\yii\queue\ErrorEvent;
|
||||
use zhuravljov\yii\queue\Queue;
|
||||
|
||||
/**
|
||||
* Sync queue driver
|
||||
@ -16,9 +21,64 @@ use zhuravljov\yii\queue\sync\Driver;
|
||||
* @since 1.2
|
||||
* @author Luke
|
||||
*/
|
||||
class Sync extends Driver
|
||||
class Sync extends Queue
|
||||
{
|
||||
|
||||
/**
|
||||
* @var boolean
|
||||
*/
|
||||
public $handle = true;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $messages = [];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
|
||||
parent::init();
|
||||
|
||||
if ($this->handle) {
|
||||
Yii::$app->on(Application::EVENT_AFTER_REQUEST, function () {
|
||||
ob_start();
|
||||
$this->run();
|
||||
|
||||
// Important, breaks downloads
|
||||
ob_end_clean();
|
||||
});
|
||||
}
|
||||
|
||||
Event::on(Queue::class, Queue::EVENT_AFTER_ERROR, function(ErrorEvent $errorEvent) {
|
||||
/* @var $exception \Expection */
|
||||
$exception = $errorEvent->error;
|
||||
Yii::error('Could not execute queued job! Message: ' . $exception->getMessage() . ' Trace:' . $exception->getTraceAsString(), 'queue');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs all jobs from queue.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
while (($message = array_shift($this->messages)) !== null) {
|
||||
$this->handleMessage($message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
protected function sendMessage($message, $timeout)
|
||||
{
|
||||
if ($timeout) {
|
||||
throw new NotSupportedException('Delayed work is not supported in the driver.');
|
||||
}
|
||||
|
||||
$this->messages[] = $message;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -126,12 +126,8 @@ $config = [
|
||||
'clients' => [],
|
||||
],
|
||||
'queue' => [
|
||||
'class' => 'humhub\components\queue\Queue',
|
||||
'driver' => [
|
||||
//'class' => 'humhub\components\queue\driver\MySQL',
|
||||
'class' => 'humhub\components\queue\driver\Sync',
|
||||
],
|
||||
],
|
||||
'live' => [
|
||||
'class' => 'humhub\modules\live\components\Sender',
|
||||
'driver' => [
|
||||
|
19
protected/humhub/migrations/m170307_170300_queuelater.php
Normal file
19
protected/humhub/migrations/m170307_170300_queuelater.php
Normal file
@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use yii\db\Migration;
|
||||
|
||||
class m170307_170300_queuelater extends Migration
|
||||
{
|
||||
|
||||
public function up()
|
||||
{
|
||||
$this->addColumn('queue', 'timeout', $this->integer()->defaultValue(0)->notNull()->after('created_at'));
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
echo "m170307_170300_queuelater cannot be reverted.\n";
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user