承接 setono/cron-builder 相关项目开发

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

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

setono/cron-builder

Composer 安装命令:

composer require setono/cron-builder

包简介

Generate a crontab from a config directory

README 文档

README

Latest Version Software License Build Status Coverage Status Mutation testing

Build your crontab from configuration files in your repository. The configuration files are written in PHP and can be placed anywhere in your repository.

Installation

composer require setono/cron-builder

Usage

The following two code snippets outline the simplest usage of the cron builder.

1. Add your commands

<?php
# etc/cronjobs/jobs.php

declare(strict_types=1);

use Setono\CronBuilder\Context;
use Setono\CronBuilder\CronJob;

return static function (Context $context): iterable {
    yield new CronJob('0 0 * * *', '/usr/bin/php {{ release_path }}/send-report.php {{ args|join(" ") }}', 'Run every day at midnight');

    if ($context->get('env') === 'prod') {
        yield new CronJob('0 0 * * *', '/usr/bin/php {{ release_path }}/process.php {{ args|join(" ") }}');
    }
};

Notice the {{ release_path }} and {{ args|join(" ") }} placeholders. These are placeholders that will be replaced with the values from the context array. This is done using the Twig templating engine, which means you can use all the features of Twig in your cronjob definitions.

If the placeholders contain any character(s) that will be interpreted by Twig (e.g. /), you can use the context Twig function like so:

yield new CronJob('0 0 * * *', '{{ context("bin/php") }} {{ release_path }}/process.php');

2. Build the crontab

When your cronjobs are defined, you can output the crontab file:

<?php
use Setono\CronBuilder\CronBuilder;
use Symfony\Component\Finder\Finder;

echo (new CronBuilder(__DIR__ . '/etc/cronjobs', [
    'release_path' => '/home/johndoe/public_html',
    'env' => 'prod',
    'args' => ['--verbose'],
]))->build();

This will output the following:

###> Automatically generated by Setono Cron Builder - DO NOT EDIT ###
0 0 * * * /usr/bin/php /home/johndoe/public_html/send-report.php --verbose # Run every day at midnight
0 0 * * * /usr/bin/php /home/johndoe/public_html/process.php --verbose
###< Automatically generated by Setono Cron Builder - DO NOT EDIT ###

You can save this in a file named crontab.txt and add it to your crontab like this:

cat crontab.txt | crontab -

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2020-09-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固