最佳实践,如何安排symfony2动作 [英] best practice how to schedule symfony2 action

查看:57
本文介绍了最佳实践,如何安排symfony2动作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我基于symfony2的应用程序必须在不同的时刻和不同的频率执行一些独立的工作。例如,发送新闻通讯,编辑报告...

My application based on symfony2 has to do some standalone jobs at differents moments and differents frequencies. For exemple, sending newsletter, editing report ...

我希望能够从应用程序
中添加/编辑每个任务我的任务将非常接近

I want to be able to add/edit each task from the application My task would be very close to cron jobs and will consist to call a specific url.

关于创建每半小时或十分钟启动一次脚本的cron作业。此脚本仅执行curl命令,使女巫获得docronjob动作。此docronjobaction在symfony内部,负责获取所有任务并启动它必须执行的任务。

I think about creating a cron job that launch a script every half hour, or ten minutes. this script only do a curl command witch get a docronjob action. This docronjobaction is inside symfony and is responsible to get all the task and launch the one it has to.


  • 是否有一种更清洁的方法来实现这一目标?

  • 在文档内部,我如何发起其他行为?

  • 我如何设法将整个控制器的时限设置为0?

  • 是否已经存在执行此操作的捆绑包?

  • Is there a cleaner way to achive that ?
  • Inside the docronaction how do I launch others action ?
  • How do I manage to set the time limit to 0 for an entire controller ?
  • Does a bundle doing this allready exist ?

推荐答案

听起来您正在将任务计划存储在数据库中。没问题。对于每种不同类型的任务(例如,发送新闻通讯,保存报告),创建一个服务来执行任务。然后向该服务添加标签(例如twig.extension,但您自己的标签),这样您就可以像TaskChain这样知道所有任务。

It sounds you are storing your schedule of tasks in the database. No problem. For every different type of task (eg. sending newsletter, save reports) create a service, which does the task. Then add to this services a tag (like twig.extension, but your own), so you have something like a TaskChain, which knows all the tasks.

用于执行创建控制台命令,该命令将从数据库中检索计划,加载TaskChain并执行任务。可以从cronjob中简单地调用此控制台命令,而无需将其公开给网络。实际上,您是通过php-cli而不是浏览器来调用此命令的,标准时间限制是无限的。

For executing create a console command, which retrieves the schedule from the database, loads the TaskChain, and executes the tasks. This console command can be simply called from a cronjob without exposing it to the web. In fact your are calling this command via the php-cli and not from a browser, the standard time limit is unlimited. No controllers should be involved for executing.

这应该全部组织在一个额外的TaskBundle中。

This should be all organized in an extra TaskBundle.

这篇关于最佳实践,如何安排symfony2动作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆