hdgarau/runners

控制类似Laravel迁移的运行过程

2.0.0 2024-02-01 15:23 UTC

This package is auto-updated.

Last update: 2024-08-30 16:26:09 UTC


README

描述

从Laravel存储运行过程的包。您可以运行N次一个过程(默认为一次)

安装

composer require hdgarau/runners

# if you use DB Model (eloquent by default)
php artisan runner:tables
php artisan migrate

处理器类

配置文件

您可以为存储运行数据定义自己的模型。该包提供两种模型:“eloquent”(默认)和“file”。您可以在环境变量RUNNER_MODEL上定义模型。该模型必须实现iRunnerModel接口。

<?php
    return [
        'default' => env('RUNNER_MODEL','eloquent'),
        'path' => database_path ('runners/'),
        'table' => 'runners',
        'models' => [
            'eloquent' => [
                'class' => \Hdgarau\Runners\RunnerModel::class,
                'params' => []
            ],
            'file' => [
                'class' => \Hdgarau\Runners\RunnerFileModel::class,
                'params' => [ storage_path('runner-data.json') ]
            ],
        ]
    ];

运行者方法

\Hdgarau\Runners\RunnerHandler       

# Execute without check. if $store is false, Runner will not registred
static public function run( string $className, array $params = [],bool $store = true ) : bool

# Execute if it never was executed
static public function once( string $className, array $params = [] ) : bool

# Execute if it was count times executed lower than $times 
static public function times( string $className, int $times, array $params = [] ) : bool

控制台

创建新进程

创建一个新的运行者

php artisan make:runner [NAME]

创建一个新的运行者(该运行者将每次运行)

php artisan make:runner --always [NAME]

运行

运行所有创建的运行者

php artisan runner

重置状态

删除所有存储

php artisan runner:clear