nanjingboy/schedule

一个简单的工具,提供了一种简单的方式来编写和部署cron作业

v0.1.0 2015-05-15 06:50 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:49:14 UTC


README

安排

一个简单的工具,提供了一种简单的方式来编写和部署cron作业。

入门

这里假设您的应用程序目录路径是:/Users/tom/workspace/test

  • cd /Users/tom/workspace/test
  • 创建composer.json文件
{
    "require": {
        "php": ">=5.4.0",
        "nanjingboy/schedule": "*"
    },
    "config": {
        "bin-dir": "bin/"
    }
}
  • 通过composer安装它
  • bin/schedule init # 创建一个初始的schedule.php文件来定义cron作业

示例schedule.php文件

<?php
use Schedule\Scheduler;

$scheduler = Scheduler::instance();

$schedule->cron()->every()->months($months)->daysOfTheMonth($daysOfTheMonth)->daysOfTheWeek($daysOfTheWeek)->hours($hours)->minutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyMinutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyHours($hours)->minutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyDays($days)->hours($hours)->minutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyMonths($months)->daysOfTheMonth($daysOfTheMonth)->daysOfTheWeek($daysOfTheWeek)->hours($hours)->minutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyYear()->daysOfTheMonth($daysOfTheMonth)->daysOfTheWeek($daysOfTheWeek)->hours($hours)->minutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyWeek()->months($months)->hours($hours)->minutes($minutes)->command($command, $options = array());

$scheduler->cron()->everyWeekday()->months($months)->hours($hours)->minutes($minutes)->command($command, $logOptions = array());

$scheduler->cron()->everyWeekend()->months($months)->hours($hours)->minutes($minutes)->command($command, $logOptions = array());
  • $minutes必须在1到59之间。
  • $hours必须在1到23之间。
  • $daysOfTheMonth必须在1到30之间。
  • $daysOfTheWeek必须在0到7之间。
  • $months必须在1到12之间。
  • $logOptions
    • log: 将STDOUT和STDERR输出到给定的路径。
    • standard_log: 将STDOUT输出到给定的路径。
    • error_log: 将STDERR输出到给定的路径。
    • 如果设置log,standard_log,error_log的值为null,则将STDOUT或STDERR输出到/dev/null。
  • $minutes, $hours, $daysOfTheMonth, $daysOfTheWeek, $months的值可以设置为单个整数或数组,而以every开头的方法只能设置单个整数。
  • 除了以every开头的方法必须调用外,其他都是可选的。
  • 您可以将命令方法替换为文件,更多信息请参见文件调用

环境

  • 如果当前目录中存在*.env文件(文件名将读取自ENV环境),则默认环境将从该文件中读取。
  • 您还可以设置SCHEDULE_ENV_FILE环境变量以指定特殊的*.env文件。
  • 如果未设置ENV和SCHEDULE_ENV_FILE,则默认环境将从当前目录中的.env文件(如果存在)中读取。
  • 示例请参见:test.env

命令行界面

$ bin/schedule

schedule version 0.1.0

Usage:
 command [options] [arguments]

Options:
 --help (-h)           Display this help message
 --quiet (-q)          Do not output any message
 --verbose (-v|vv|vvv) Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug
 --version (-V)        Display this application version
 --ansi                Force ANSI output
 --no-ansi             Disable ANSI output
 --no-interaction (-n) Do not ask any interactive question

Available commands:
 clear   Clear cron jobs that defined in schedule.php file from crontab
 help    Displays help for a command
 init    Create an initial schedule.php file
 list    Lists commands
 write   Write cron jobs that defined in schedule.php file to crontab

许可证

MIT