Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ignatenkovnikita committed Aug 18, 2020
2 parents a4ddeae + 4942a62 commit cd601e0
Show file tree
Hide file tree
Showing 20 changed files with 434 additions and 40 deletions.
14 changes: 0 additions & 14 deletions AutoloadExample.php

This file was deleted.

4 changes: 2 additions & 2 deletions Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
namespace ignatenkovnikita\queuemanager;


use yii\base\BaseObject;
use yii\base\InvalidConfigException;
use yii\base\Object;

class Job extends Object
class Job extends BaseObject
{
public $name;

Expand Down
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2018 Nikita Ignatenkov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
38 changes: 37 additions & 1 deletion QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,52 @@

namespace ignatenkovnikita\queuemanager;


use Yii;
use yii\base\Application;
use yii\base\BootstrapInterface;
use yii\base\Event;
use yii\base\Module;
use yii\filters\AccessControl;
use yii\helpers\ArrayHelper;
use yii\queue\Queue;

class QueueManager extends Module implements BootstrapInterface
{
public $adminPermission = 'queuemanager-module';

public function behaviors()
{
return ArrayHelper::merge(
parent::behaviors(),
[
'access' => [
'class' => AccessControl::className(),
'rules' => [
[
'allow' => true,
'roles' => [$this->adminPermission]
]
]
]
]
);
}

public function init()
{
parent::init(); // TODO: Change the autogenerated stub
$this->registerTranslations();
}

public function registerTranslations()
{
Yii::$app->i18n->translations['queuemanager'] = [
'class' => 'yii\i18n\PhpMessageSource',
'sourceLanguage' => 'en-US',
'basePath' => '@vendor/ignatenkovnikita/yii2-queuemanager/messages',
];

}

public function bootstrap($app)
{
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Yii2 Queue Manager
==================

[![Latest Stable Version](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/v/stable)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager) [![Total Downloads](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/downloads)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager) [![Latest Unstable Version](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/v/unstable)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager) [![License](https://poser.pugx.org/ignatenkovnikita/yii2-queuemanager/license)](https://packagist.org/packages/ignatenkovnikita/yii2-queuemanager)


Yii2 Queue Manager

![2017-10-21_13-55-13](https://user-images.githubusercontent.com/4436320/31851112-b75f26e8-b667-11e7-8f54-d907daeb26bb.png)
Expand Down
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
}
],
"require": {
"yiisoft/yii2": "*"
"yiisoft/yii2": "~2.0.0",
"yiisoft/yii2-jui": "~2.0.0",
"2amigos/yii2-chartjs-widget": "~2.0"
},
"autoload": {
"psr-4": {
Expand Down
13 changes: 12 additions & 1 deletion controllers/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
*/
class DefaultController extends Controller
{
/**
* @return array
*/
public function behaviors()
{
return [
Expand Down Expand Up @@ -68,12 +71,15 @@ protected function getWorkersInfo()
}


/**
* @return array
*/
public function actionAjax()
{
$workers = [];
if ($workersInfo = $this->getWorkersInfo()) {
foreach ($workersInfo as $name => $info) {
$workers[] = $name .' '.$info['addr'];
$workers[] = $name . ' ' . $info['addr'];
// Console::stdout($this->format("- $name: ", Console::FG_YELLOW));
// Console::output($info['addr']);
}
Expand Down Expand Up @@ -104,6 +110,11 @@ public function actionStat()
return $this->render('stat');
}

public function actionReport()
{
return $this->render('report');
}

/**
* Displays a single QueueManager model.
* @param integer $id
Expand Down
42 changes: 42 additions & 0 deletions messages/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
/**
* Configuration file for 'yii message/extract' command.
*
* This file is automatically generated by 'yii message/config' command.
* It contains parameters for source code messages extraction.
* You may modify this file to suit your needs.
*
* You can use 'yii message/config-template' command to create
* template configuration file with detailed description for each parameter.
*/
return [
'color' => null,
'interactive' => true,
'help' => null,
'sourcePath' => '@vendor/ignatenkovnikita/yii2-queuemanager',
'messagePath' => 'vendor/ignatenkovnikita/yii2-queuemanager/messages/',
'languages' => ['en', 'ru'],
'translator' => 'Yii::t',
'sort' => false,
'overwrite' => true,
'removeUnused' => false,
'markUnused' => true,
'except' => [
'.svn',
'.git',
'.gitignore',
'.gitkeep',
'.hgignore',
'.hgkeep',
'/messages',
'/BaseYii.php',
],
'only' => [
'*.php',
],
'format' => 'php',
'catalog' => 'messages',
'ignoreCategories' => [],
'phpFileHeader' => '',
'phpDocBlock' => null,
];
52 changes: 52 additions & 0 deletions messages/en/queuemanager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yii message/extract' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'Are you sure to repeat this item?' => '',
'Are you sure you want to delete this item?' => '',
'Class' => '',
'Create' => '',
'Create {modelClass}' => '',
'Created At' => '',
'Data' => '',
'Delay' => '',
'Delete' => '',
'End Execute' => '',
'ID' => '',
'Name' => '',
'Priority' => '',
'Properties' => '',
'Queue Managers' => '',
'Repeat' => '',
'Reset' => '',
'Result' => '',
'Result ID' => '',
'Search' => '',
'Sender' => '',
'Start Execute' => '',
'Status' => '',
'Status Done' => '',
'Status Error' => '',
'Status Reserved' => '',
'Status Waiting' => '',
'Time Execute' => '',
'Ttr' => '',
'Update' => '',
'Update {modelClass}: ' => '',
'Updated At' => '',
];
55 changes: 55 additions & 0 deletions messages/ru/queuemanager.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Message translations.
*
* This file is automatically generated by 'yii message/extract' command.
* It contains the localizable messages extracted from source code.
* You may modify this file by translating the extracted messages.
*
* Each array element represents the translation (value) of a message (key).
* If the value is empty, the message is considered as not translated.
* Messages that no longer need translation will have their translations
* enclosed between a pair of '@@' marks.
*
* Message string can be used with plural forms format. Check i18n section
* of the guide for details.
*
* NOTE: this file must be saved in UTF-8 encoding.
*/
return [
'Report' => 'Отчет',
'Statistics' => 'Статистика',
'Enter date' => 'Укажите дату',
'Are you sure to repeat this item?' => '',
'Are you sure you want to delete this item?' => '',
'Class' => '',
'Create' => '',
'Create {modelClass}' => '',
'Created At' => '',
'Data' => '',
'Delay' => '',
'Delete' => '',
'End Execute' => '',
'ID' => '',
'Name' => '',
'Priority' => '',
'Properties' => '',
'Queue Managers' => '',
'Repeat' => '',
'Reset' => '',
'Result' => '',
'Result ID' => '',
'Search' => '',
'Sender' => '',
'Start Execute' => '',
'Status' => '',
'Status Done' => '',
'Status Error' => '',
'Status Reserved' => '',
'Status Waiting' => '',
'Time Execute' => '',
'Ttr' => '',
'Update' => '',
'Update {modelClass}: ' => '',
'Updated At' => '',
];
2 changes: 1 addition & 1 deletion models/generated/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class QueueManager extends \yii\db\ActiveRecord
*/
public static function tableName()
{
return 'queue_manager';
return '{{%queue_manager}}';
}

/**
Expand Down
23 changes: 21 additions & 2 deletions models/search/QueueManagerSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use yii\base\Model;
use yii\data\ActiveDataProvider;
use ignatenkovnikita\queuemanager\models\QueueManager;
use yii\db\ActiveQuery;

/**
* QueueManagerSearch represents the model behind the search form about `ignatenkovnikita\queuemanager\models\QueueManager`.
Expand Down Expand Up @@ -57,12 +58,15 @@ public function search($params)
'delay' => $this->delay,
'priority' => $this->priority,
'result_id' => $this->result_id,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
// 'created_at' => $this->created_at,
// 'updated_at' => $this->updated_at,
'start_execute' => $this->start_execute,
'end_execute' => $this->end_execute,
]);

$this->dayCondition($query, 'created_at');
$this->dayCondition($query, 'updated_at');

$query->andFilterWhere(['like', 'name', $this->name])
->andFilterWhere(['like', 'sender', $this->sender])
->andFilterWhere(['like', 'status', $this->status])
Expand All @@ -74,4 +78,19 @@ public function search($params)

return $dataProvider;
}


/**
* @param ActiveQuery $query
* @param $attribute
* @return bool
*/
protected function dayCondition(ActiveQuery &$query, $attribute)
{
if(empty($this->{$attribute})) {
return false;
}
$start = strtotime('midnight', strtotime($this->{$attribute}));
$query->andFilterWhere( ['BETWEEN', $attribute, $start, strtotime('+1day - 1sec', $start)]);
}
}
2 changes: 1 addition & 1 deletion views/default/_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
<?php echo $form->field($model, 'end_execute')->textInput() ?>

<div class="form-group">
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
<?php echo Html::submitButton($model->isNewRecord ? Yii::t('queuemanager', 'Create') : Yii::t('queuemanager', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
4 changes: 2 additions & 2 deletions views/default/_search.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
<?php // echo $form->field($model, 'end_execute') ?>

<div class="form-group">
<?php echo Html::submitButton(Yii::t('app', 'Search'), ['class' => 'btn btn-primary']) ?>
<?php echo Html::resetButton(Yii::t('app', 'Reset'), ['class' => 'btn btn-default']) ?>
<?php echo Html::submitButton(Yii::t('queuemanager', 'Search'), ['class' => 'btn btn-primary']) ?>
<?php echo Html::resetButton(Yii::t('queuemanager', 'Reset'), ['class' => 'btn btn-default']) ?>
</div>

<?php ActiveForm::end(); ?>
Expand Down
Loading

0 comments on commit cd601e0

Please sign in to comment.