frcho/crontask 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

frcho/crontask

Composer 安装命令:

composer require frcho/crontask

包简介

The easy way to realize cron task using Symfony 4, 5

README 文档

README

Creating new cron jobs for every trivial tasks is a time-consuming task, though. And depending on the environment your application will be hosted in, you may not always be able to add a cron job to the system whenever you feel like it.

Installation

Step 1: Download the Bundle

Open a command console and execute the following command to download the latest stable version of this bundle:

$ composer require frcho/crontask 1.1.0

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Implementing interval-based cron tasks in Symfony5 using Symfony commands and a Doctrine entity

The Doctrine entity known as the 'CronTask'

If we review the requirements real quick, we'll notice that we want our tasks to be able to do the following:

Run at a specified interval Perform certain actions

This sounds as simple as it is. To begin with, we'll create a CronTask entity we can persist to our database. This entity should be contain an array of actions it can execute. We'll be using Symfony commands as our actions. It'd also be handy if each task had its own identifier.

Create your command

<?php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;

class CronTasksDefaultCommand extends Command
{

    protected function configure()
    {

        $this->setName('crontasks:default')->setDescription('Creates the commands by default in database.');
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {

        set_time_limit(0);
        ini_set('memory_limit', '-1');
        $container = $this->getApplication()->getKernel()->getContainer();
        $defaultCommands = array(
            array(
                "name" => "Example asset symlinking task",
                "interval" => 2, // Run once every 2 minutes,
                "range" => 'minutes',
                "commands" => 'assets:install --symlink web',
                "isHide" => false, /* "isHide == true, if you have enable view for this bundle, This command doesn't show in the view schedule task" */
                "enabled" => true
            ),
            array(
                "name" => "Example asset task",
                "interval" => 1, // Run once every hour
                "range" => 'hours',
                "commands" => 'cache:clear',
                "enabled" => false
            ),
        );

        $container->get('frcho.crontask_default')->setArrayCommands($defaultCommands);
        return 0;
    }
}

##Note: range support:

  • minutes
  • hours
  • days

Usage

The command to run other commands

$ php bin/console crontasks:run

The command to populate de database, with the commands to run by crontask:run

$ php bin/console crontasks:default

After execute crontasks:default, you should now have a single CronTask in your database, ready to be executed.

Now, you could execute php bin/console crontasks:run yourself. Or add that command as an actual cron job that is executed once every few minutes like so:

$ crontab -e
Now add your cron job:

# Run every five minutes
*/5 * * * * php path-your-project/bin/console crontasks:run

And there you have it.
One task to rule them all.

Update the database schema :

bin/console doctrine:schema:update --force

License

This bundle is under the MIT license

frcho/crontask 适用场景与选型建议

frcho/crontask 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.58k 次下载、GitHub Stars 达 5, 最近一次更新时间为 2016 年 02 月 28 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「symfony」 「cron」 「task」 「crontab」 「jobs」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 frcho/crontask 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 frcho/crontask 我们能提供哪些服务?
定制开发 / 二次开发

基于 frcho/crontask 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 6.58k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 5
  • 点击次数: 16
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-02-28