oudirichi/scheduler

Whenever gem 的 PHP 版本。

v1.0.0 2017-04-30 04:10 UTC

This package is not auto-updated.

Last update: 2024-09-25 01:30:24 UTC


README

安装

使用以下命令安装最新版本以供全局使用

$ composer global require oudirichi/scheduler

或按项目

$ composer require oudirichi/scheduler

入门

$ cd /apps/my-great-project

# for global
$ shedulerize

# for specific project
$ vendor/bin/shedulerize

这将为您创建一个初始的 config/schedule.php 文件。

scheduler 命令

$ cd /apps/my-great-project

$ scheduler

这只会显示您的 schedule.rb 文件转换为 cron 语法。它不会读取或写入您的 crontab 文件;您需要这样做才能使作业执行

$ scheduler --update-crontab

定义自己的作业类型

<?php
Scheduler\job_type("pewpew", "cd :path && :task");

Scheduler\every("* * * * *", function($cron) {
  $cron->pewpew('echo "pewpew" >> log/test.log');
});

Cron 格式

* * * * * *
| | | | | |
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 0-6 OR 1-7, 0 and 7 both stand for Sunday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)