Added queuing component

This commit is contained in:
Lucas Bartholemy 2017-01-18 12:48:47 +01:00
parent 0b6a7b2362
commit e149b8be7e
8 changed files with 137 additions and 9 deletions

View File

@ -28,6 +28,7 @@
"nqxcode/zendsearch": "^2.0",
"xj/yii2-jplayer-widget": "*",
"zendframework/zend-ldap": "^2.5",
"zhuravljov/yii2-queue": "^0.7",
"bower-asset/jquery-timeago": "1.4.*",
"bower-asset/jquery-nicescroll": "3.6.*",
"bower-asset/jquery-knob": "1.2.*",

View File

@ -12,7 +12,6 @@ use Yii;
use yii\console\Controller;
use yii\helpers\Console;
/**
* Cronjobs
*
@ -40,9 +39,7 @@ class CronController extends Controller
$this->trigger(self::EVENT_ON_HOURLY_RUN);
$this->stdout("\n\nAll cron tasks finished.\n\n", Console::FG_GREEN);
Yii::$app->settings->set('cronLastHourlyRun', time());
return self::EXIT_CODE_NORMAL;
}
@ -55,9 +52,7 @@ class CronController extends Controller
$this->trigger(self::EVENT_ON_DAILY_RUN);
$this->stdout("\n\nAll cron tasks finished.\n\n", Console::FG_GREEN);
Yii::$app->settings->set('cronLastDailyRun', time());
return self::EXIT_CODE_NORMAL;
}

View File

@ -0,0 +1,27 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\components\queue;
use yii\base\Object;
use zhuravljov\yii\queue\Job;
/**
* ActiveJob
*
* @since 1.2
* @author Luke
*/
abstract class ActiveJob extends Object implements Job
{
/**
* Runs this job
*/
abstract public function run();
}

View File

@ -0,0 +1,22 @@
<?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 zhuravljov\yii\queue\Queue as BaseQueue;
/**
* Queue
*
* @since 1.2
* @author Luke
*/
class Queue extends BaseQueue
{
}

View File

@ -0,0 +1,24 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\components\queue\driver;
use zhuravljov\yii\queue\db\Driver;
/**
* MySQL queue driver
*
* @since 1.2
* @author Luke
*/
class MySQL extends Driver
{
public $mutex = 'yii\mutex\MysqlMutex';
}

View File

@ -0,0 +1,24 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\components\queue\driver;
use zhuravljov\yii\queue\sync\Driver;
/**
* Sync queue driver
*
* @since 1.2
* @author Luke
*/
class Sync extends Driver
{
public $handle = true;
}

View File

@ -10,7 +10,7 @@ $config = [
'name' => 'HumHub',
'version' => '1.2.0-dev',
'basePath' => dirname(__DIR__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR,
'bootstrap' => ['log', 'humhub\components\bootstrap\ModuleAutoLoader'],
'bootstrap' => ['log', 'humhub\components\bootstrap\ModuleAutoLoader', 'queue'],
'sourceLanguage' => 'en',
'components' => [
'moduleManager' => [
@ -121,6 +121,13 @@ $config = [
'class' => 'humhub\modules\user\authclient\Collection',
'clients' => [],
],
'queue' => [
'class' => humhub\components\queue\Queue::class,
'driver' => [
//'class' => 'humhub\components\queue\driver\MySQL',
'class' => 'humhub\components\queue\driver\Sync',
],
],
],
'params' => [
'installed' => false,
@ -217,7 +224,4 @@ $config = [
]
];
return $config;

View File

@ -0,0 +1,31 @@
<?php
use yii\db\Migration;
class m170118_111823_queuetable extends Migration
{
public $tableName = '{{%queue}}';
public $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';
public function up()
{
$this->createTable($this->tableName, [
'id' => $this->primaryKey(),
'channel' => $this->string()->notNull(),
'job' => $this->binary()->notNull(),
'created_at' => $this->integer()->notNull(),
'started_at' => $this->integer(),
'finished_at' => $this->integer(),
], $this->tableOptions);
$this->createIndex('channel', $this->tableName, 'channel');
$this->createIndex('started_at', $this->tableName, 'started_at');
}
public function down()
{
$this->dropTable($this->tableName);
}
}