micahpotter/laravel-enhanced-scheduler

此包的最新版本(dev-master)没有可用的许可信息。

为Laravel的调度器提供增强的日志记录和分布式功能。

dev-master 2020-08-19 15:15 UTC

This package is auto-updated.

Last update: 2024-09-20 02:13:32 UTC


README

安装

添加Myriad仓库

此包通过Satis内部分发。首先将仓库添加到composer.json

  "repositories": [
    {
      "type": "composer",
      "url": "https://satis.myriadmobile.com"
    }
  ]

需求依赖

使用以下命令通过composer要求此包

composer require myriad/laravel-enhanced-scheduler

安装服务提供者

更新composer后,将服务提供者添加到config/app.php中的providers数组

Myriad\Illuminate\Console\Scheduling\EnhancedSchedulerServiceProvider::class,

发布迁移

您不必创建自己的迁移,可以使用包中的迁移

php artisan vendor:publish --provider=myriad/laravel-enhanced-scheduler --tag=migrations

使用特性

最后,要使调度器实际使用增强的调度器,只需在app/Console/Kernel.php中使用该特性

<?php

namespace App\Console;

use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Foundation\Console\Kernel as ConsoleKernel;
use Myriad\Illuminate\Console\Scheduling\EnhancedScheduler;

class Kernel extends ConsoleKernel {

  use EnhancedScheduler;
  
  ...
  
}

配置

增强调度器旨在无需额外配置即可直接使用。如果您需要编辑配置,请将配置文件发布到config目录

php artisan vendor:publish --provider=myriad/laravel-enhanced-scheduler --tag=config

用法

使用增强调度器的方式与Laravel调度器相同。只需在schedules方法中注册您的计划即可!

新方法

->withoutDistributedOverlapping($task)

使用分布式锁定机制确保事件只在集群中的一个节点上运行。$task应该是一个唯一的名称,用于在集群中标识条目。例如my-nightly-task

->withoutLog()

当您不希望事件被记录时使用。

->withoutLogOutput()

当您想要记录事件但不记录输出时使用。这对于输出非常长的事件或您根本不关心输出时非常有用。

->failOnNonZeroExit($task)

用于确保命令干净地退出。仅用于命令。