From e149b8be7ee3d473437dafb5f55fea154bd1bb24 Mon Sep 17 00:00:00 2001 From: Lucas Bartholemy Date: Wed, 18 Jan 2017 12:48:47 +0100 Subject: [PATCH] Added queuing component --- composer.json | 1 + protected/humhub/commands/CronController.php | 5 --- .../humhub/components/queue/ActiveJob.php | 27 ++++++++++++++++ protected/humhub/components/queue/Queue.php | 22 +++++++++++++ .../humhub/components/queue/driver/MySQL.php | 24 ++++++++++++++ .../humhub/components/queue/driver/Sync.php | 24 ++++++++++++++ protected/humhub/config/common.php | 12 ++++--- .../migrations/m170118_111823_queuetable.php | 31 +++++++++++++++++++ 8 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 protected/humhub/components/queue/ActiveJob.php create mode 100644 protected/humhub/components/queue/Queue.php create mode 100644 protected/humhub/components/queue/driver/MySQL.php create mode 100644 protected/humhub/components/queue/driver/Sync.php create mode 100644 protected/humhub/migrations/m170118_111823_queuetable.php diff --git a/composer.json b/composer.json index 0178ae0d7b..0ec864773e 100644 --- a/composer.json +++ b/composer.json @@ -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.*", diff --git a/protected/humhub/commands/CronController.php b/protected/humhub/commands/CronController.php index a4c569d13c..a72c92854b 100644 --- a/protected/humhub/commands/CronController.php +++ b/protected/humhub/commands/CronController.php @@ -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; } diff --git a/protected/humhub/components/queue/ActiveJob.php b/protected/humhub/components/queue/ActiveJob.php new file mode 100644 index 0000000000..ac7056b3fb --- /dev/null +++ b/protected/humhub/components/queue/ActiveJob.php @@ -0,0 +1,27 @@ + '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; diff --git a/protected/humhub/migrations/m170118_111823_queuetable.php b/protected/humhub/migrations/m170118_111823_queuetable.php new file mode 100644 index 0000000000..6228161c6e --- /dev/null +++ b/protected/humhub/migrations/m170118_111823_queuetable.php @@ -0,0 +1,31 @@ +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); + } + +}