slavkluev / yii2-job-progress
A Yii2 extension lets you know the progress of the job in a queue.
Installs: 63
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:yii2-extension
Requires
- php: ~7.2
- yiisoft/yii2-queue: ^2.3
Requires (Dev)
- phpunit/phpunit: >=8.0
- squizlabs/php_codesniffer: ^3.0
This package is auto-updated.
Last update: 2024-11-26 22:31:16 UTC
README
A Yii2 extension lets you know the progress of the job in a queue.
Install
Via Composer
$ composer require slavkluev/yii2-job-progress
You need to add progress behavior for queue component. Update config file:
'components' => [ 'queue' => [ // ... 'as progress' => \slavkluev\JobProgress\ProgressBehavior::class, ], ],
To add migrations to your application, edit the console config file to configure a namespaced migration:
'controllerMap' => [ // ... 'migrate' => [ 'class' => 'yii\console\controllers\MigrateController', 'migrationPath' => null, 'migrationNamespaces' => [ // ... 'slavkluev\JobProgress\migrations', ], ], ],
Then apply new migrations:
$ yii migrate
Usage
class TestJob extends BaseObject implements \yii\queue\JobInterface { public function execute($queue) { \Yii::$app->queue->setProgressMax(100); for ($i = 0; $i < 100; $i++) { \Yii::$app->queue->incrementProgress(); sleep(1); } } }
If the job is completed and removed, you can find out the progress by $jobId.
$jobProgress = JobProgress::findByJobId($jobId); echo $jobProgress->getProgressMax() . PHP_EOL; echo $jobProgress->getProgressNow() . PHP_EOL; echo $jobProgress->getPercent() . PHP_EOL;
Documentations
// JobProgress methods $jobProgress->getProgressMax(); // Integer $jobProgress->getProgressNow(); // Integer $jobProgress->getPercent(); // Float // Queue methods (Call from your Job) \Yii::$app->queue->setProgressMax(int $value); // Update the max number of progress. \Yii::$app->queue->setProgressNow(int $value); // Update the current number of progress. \Yii::$app->queue->incrementProgress(int $offset); // Increase current number of progress by $offset. \Yii::$app->queue->getProgressMax(); // Integer \Yii::$app->queue->getProgressNow(); // Integer \Yii::$app->queue->getPercent(); // Float
Testing
$ composer test
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Security
If you discover any security related issues, please email slavkluev@yandex.ru instead of using the issue tracker.
Credits
License
The MIT License (MIT). Please see License File for more information.