承接 juanchosl/cronjobs 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

juanchosl/cronjobs

Composer 安装命令:

composer require juanchosl/cronjobs

包简介

Little methods collection in order to create and automated execution of commands as cronjobs

README 文档

README

Description

Little methods collection in order to declare some Command as Cronjobs and execute it when the programm time have a coincidence. This is an extension of the Terminal library.

Install

composer require juanchosl/cronjobs

How to use

Config

Commands

First, you need to create the desired Command to execute. Visit the Terminal library for show how create Commands. The commands can be reused from your own terminal app.

Inputs

The commands receive the arguments from console, for this reason you need to create an Input entity for declare manually the values to send to the cronjob

$input = new Input;
$input->addArgument('required_single', 'value');
$input->addArgument('required_void', null);
$input->addArgument('required_multi', ['a', 'b', 'c']);

Programming

In order to set the execution time, needs to create a standard time config using a ProgrammingInterface for declare when the Cronjobs need to be executed You can use the cron standar syntax, the * value is the default value when it is not setted:

$programming = (new Programming)->setHour('*/2');
$programming = (new Programming)->setHour('15,30,45,0');
$programming = (new Programming)->setHour('6');

Crontab

Create the script to call from your crontab console app every minute (or when you wont) and mount a Crontab app, adding your cronjobs

include dirname(__DIR__, 1) . DIRECTORY_SEPARATOR . 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';

$logger = new Logger((new FileRepository(LOGS_DIR . DIRECTORY_SEPARATOR . 'cronjobs.log'))->setComposer(new TextComposer));

$app = new Crontab;
$app->setLogger($logger);
$app->setDebug(true);
$app->add(new FirstCommand, (new Input)->addArgument('argument', 'value'), (new Programming)->setHour('*/2')); //Execute every hours multiple of 2
$app->add(new SecondCommand, (new Input)->addArgument('argument', 'value'), (new Programming)->setDayOfWeek(0)); //Execute the first day of week, 0 is Sunday
$app->add(new ThirdCommand, (new Input)->addArgument('argument', 'value'), (new Programming)->setDayOfMonth(1)); //Execute the first day of month
$app->run();

统计信息

  • 总下载量: 8
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-12-26