https://groups.google.com/forum/#!topic/python-tornado/KEmAg97zUg8

鉴于不是所有人都能跨越GFW,摘抄如下:

 Scheduled jobs in Tornado
7 名作者发布了 9 个帖子
Robert Wikman
12/2/6
将帖子翻译为中文
Hello, I'm trying to figure out how to write a scheduler to run jobs at
specific times, i.e. every day at 5 PM, in Tornado.
Is there any simple way to accomplish this? Regards,
Robert Christopher Allick
12/2/7
将帖子翻译为中文
not sure if this helps, but you could create a cron job that hits a webservice and setup a handler in your application. you might want to protect the call.
- 隐藏引用文字 - On Feb 6, 2012, at 9:34 AM, rbw wrote: > Hello,
>
> I'm trying to figure out how to write a scheduler to run jobs at
> specific times, i.e. every day at 5 PM, in Tornado.
> Is there any simple way to accomplish this?
>
> Regards,
> Robert
> bergundy
12/2/7
将帖子翻译为中文
Wasn't planning on releasing it, but what the heck :) https://github.com/bergundy/tornado_crontab
- 隐藏引用文字 - On Mon, Feb 6, 2012 at 7:04 PM, Christopher Allick <chris...@gmail.com> wrote: not sure if this helps, but you could create a cron job that hits a webservice and setup a handler in your application. you might want to protect the call. On Feb 6, 2012, at 9:34 AM, rbw wrote: > Hello,
>
> I'm trying to figure out how to write a scheduler to run jobs at
> specific times, i.e. every day at 5 PM, in Tornado.
> Is there any simple way to accomplish this?
>
> Regards,
> Robert
> wataka
12/2/7
将帖子翻译为中文
I use APscheduler, http://packages.python.org/APScheduler/ On Feb 6, 6:31 pm, Roey Berman <roey.ber...@gmail.com> wrote:
> Wasn't planning on releasing it, but what the heck :)
>
> https://github.com/bergundy/tornado_crontab
>
- 显示引用文字 -
Aleksandar Radulovic
12/2/7
Re: [tornado] Re: Scheduled jobs in Tornado
将帖子翻译为中文
How about just using celery? It works like a charm and its a proven
and robust solution.. - 显示引用文字 - --
a lex 13 x
http://a13x.net | @a13xnet Jason
12/2/7
将帖子翻译为中文
I'm sorry.I don't know.
- 隐藏引用文字 - On Feb 6, 10:34 pm, rbw <r...@vault13.org> wrote:
> Hello,
>
> I'm trying to figure out how to write a scheduler to run jobs at
> specific times, i.e. every day at 5 PM, in Tornado.
> Is there any simple way to accomplish this?
>
> Regards,
> Robert
Robert Wikman
12/2/7
将帖子翻译为中文
Forgot to mention that I was at the time of my first post looking for
a solution using the Tornado built-in functionality, i.e.
PeriodCallback or add_timeout. Didn't even think about using a separate module for this. Thank you everyone. Regards,
Robert On Feb 6, 7:49 pm, Aleksandar Radulovic <a...@a13x.net> wrote:
> How about just using celery? It works like a charm and its a proven
> and robust solution..
>
>
>
>
>
>
>
>
>
> On Mon, Feb 6, 2012 at 7:05 PM, wataka <nhy...@googlemail.com> wrote:
> > I use APscheduler,http://packages.python.org/APScheduler/
- 显示引用文字 -
bergundy
12/2/8
Re: [tornado] Re: Scheduled jobs in Tornado
将帖子翻译为中文
@wataka - Thanks for the APScheduler link, I was gonna write tests for my crontab project but now that I found out about that project I'm just using apscheduler.triggers.cron.CronTrigger I posted a gist if anyone is interested.
http://tornadogists.org/1770500/
- 显示引用文字 -
whitemice
12/2/11
Re: [tornado] Re: Scheduled jobs in Tornado
将帖子翻译为中文
On Mon, 2012-02-06 at 10:05 -0800, wataka wrote:
> I use APscheduler, http://packages.python.org/APScheduler/ +1 APschedular Actually I run APschedular in a process that uses AMQ to send messages
at designated times; then the apps/services just process the messages. --
System & Network Administrator [ LPI & NCLA ]
<http://www.whitemiceconsulting.com>
OpenGroupware Developer <http://www.opengroupware.us>
Adam Tauno Williams

  

http://tornadogists.com/1770500/

import re
import itertools
import logging from apscheduler.triggers.cron import CronTrigger
from tornado.ioloop import IOLoop
from datetime import datetime class CronCallback(object):
"""Schedules the given callback to be called periodically. The callback is called according to the schedule argument. `start` must be called after the CronCallback is created. If schedule is a string it should contain 7 cron fields: ('second', 'minute', 'hour', 'day', 'month', 'year', 'day_of_week').
If schedule is a dict it must contain at least one of the fields above. >>> cron1 = CronCallback(lambda: logging.error('x'), dict(seconds = 1)) # logs 'x' every second
>>> cron2 = CronCallback(lambda: IOLoop.instance().stop(), '*/5 * * * * * *') # stops ioloop every 5 seconds
>>> cron1.start()
>>> cron2.start()
>>> IOLoop.instance().start()
""" _split_re = re.compile("\s+")
_sched_seq = ('second', 'minute', 'hour', 'day', 'month', 'year', 'day_of_week') def __init__(self, callback, schedule, io_loop=None):
if isinstance(schedule, basestring):
splitted = self._split_re.split(schedule)
if len(splitted) < 7:
raise TypeError("'schedule' argument pattern mismatch") schedule = dict(itertools.izip(self._sched_seq, splitted)) self.callback = callback
self._trigger = CronTrigger(**schedule)
self.io_loop = io_loop or IOLoop.instance()
self._running = False
self._timeout = None def start(self):
"""Starts the timer."""
self._running = True
self._schedule_next() def stop(self):
"""Stops the timer."""
self._running = False
if self._timeout is not None:
self.io_loop.remove_timeout(self._timeout)
self._timeout = None def _run(self):
if not self._running: return
try:
self.callback()
except Exception:
logging.error("Error in cron callback", exc_info=True)
self._schedule_next() def _schedule_next(self):
if self._running:
self._timeout = self.io_loop.add_timeout(self._next_timeout, self._run) @property
def _next_timeout(self):
d = datetime.now()
return self._trigger.get_next_fire_time(d) - d if __name__ == "__main__":
import doctest
doctest.testmod()

  

===后记====

实际采用方案:

from apscheduler.schedulers.tornado import TornadoScheduler
scheduler = TornadoScheduler()
if run_cron: #for production
scheduler.add_job(renew_boss_user_accounts, 'cron',day='',hour='',minute='',second='', max_instances=3)
scheduler.add_job(refresh_accounts, 'cron',day='*',hour='',minute='',second='', max_instances=3)
scheduler.add_job(acount_logs_due_notification, 'cron',day='*',hour='',minute='',second='', max_instances=3)
scheduler.add_job(refresh_sale_orders, 'cron',day='*',hour='',minute='',second='', max_instances=3)
scheduler.add_job(make_file_for_cool_agent, 'cron',day='*',hour='',minute='',second='', max_instances=3)
#scheduler.add_job(refresh_sale_orders, 'cron',second='*/10', max_instances=3) scheduler.start()

tornado 排程的更多相关文章

  1. 利用 crontab 來做 Linux 固定排程

    crontab 介紹 crontab 是 Linux 內建的機制,可以根據設置的時間參數來執行例行性的工作排程. 上述這張圖可以清楚的顯示出前五項參數應該要帶進去的數字.依序是分鐘, 小時, 日期, ...

  2. apscheduler 排程

    https://apscheduler.readthedocs.org/en/v2.1.2/cronschedule.html 参数 说明 year 4位年 month 月份1-12 day 日:1- ...

  3. crontab 例行性排程

    那么我们就来聊一聊 crontab 的语法吧![root@www ~]# crontab [-u username] [-l|-e|-r]选项不参数:-u :只有 root 才能迚行这个仸务,亦即帮其 ...

  4. 例行性工作排程 (crontab)

    1. 什么是例行性工作排程 1.1 Linux 工作排程的种类: at, crontab 1.2 Linux 上常见的例行性工作2. 仅运行一次的工作排程 2.1 atd 的启动与 at 运行的方式: ...

  5. Linux Kernel 排程機制介紹

    http://loda.hala01.com/2011/12/linux-kernel-%E6%8E%92%E7%A8%8B%E6%A9%9F%E5%88%B6%E4%BB%8B%E7%B4%B9/ ...

  6. 浅尝一个排程引擎Optaplanner,前序。

    当码农有10多年了,由建筑行业软件,各种MIS,通用物流定制平台,CCTV客户端(是闭路电视,不是央视喔)啥都做过.最后小试一下创业,不过那都是闹着玩的,不到一年就回到码农的队列,重拾搬砖的行当.近些 ...

  7. Tornado 协程

    同步异步I/O客户端 from tornado.httpclient import HTTPClient,AsyncHTTPClient def ssync_visit(): http_client ...

  8. 【原】无脑操作:HTML5 + CSS + JavaScript实现比赛排程

    1.背景:朋友请帮忙做一个比赛排程软件 2.需求: ① 比赛人数未知,可以通过文本文件读取参赛人员名称: ② 对参赛人员随机分组,一组两人,两两PK,如果是奇数人数,某一个参赛人员成为幸运儿自动晋级: ...

  9. 机械加工行业计划排程:中车实施应用易普优APS

    一.机械加工行业现状 机械制造业在生产管理上的主要特点是:离散为主.流程为辅.装配为重点.机械制造业的基本加工过程是把原材料分割,大部分属于多种原材料平行加工,逐一经过车.铣.刨.磨或钣金成型等加工工 ...

随机推荐

  1. Cache-Aside Pattern解析

    使用这种模式,可以帮助我们维护Cache中的数据. 使用Cache容易遇到的问题: 使用缓存,主要是为了将一些重复访问的数据存到缓存,开发者希望缓存中的数据和数据源中的保持一致,这就需要程序中有相应的 ...

  2. Auto generating Entity classes with xsd.exe for XML Serialization and De-Serialization

    More info here: http://blogs.msdn.com/b/yojoshi/archive/2011/05/14/xml-serialization-and-deserializa ...

  3. URL中“#” “?” &“”号的作用

    URL中"#" "?" &""号的作用   阅读目录 1. # 2. ? 3. & 回到顶部 1. # 10年9月,twit ...

  4. yii2的urlManager配置

    网址伪静态是一个非常常用的网站需求,Yii2可以非常简单地进行配置. 首先,在配置文件config/main.php的'components' 段中,加入如下设置:'urlManager'=>a ...

  5. NSUserDefaults standardUserDefaults的使用

    本地存储数据简单的说有三种方式:数据库.NSUserDefaults和文件. NSUserDefaults用于存储数据量小的数据,例如用户配置.并不是所有的东西都能往里放的,只支持:NSString, ...

  6. OCS 开放缓存服务

    开放缓存服务( Open Cache Service,简称OCS)是在线缓存服务,为热点数据的访问提供高速响应.说白了,就是一款基于memcached开发的对外云缓存服务器,完全可以把OCS当成mem ...

  7. 导入excel错误:外部表不是预期的格式 解决方案

    环境:win7+iis7+Office2007 在asp.net网站中导出Excel文件后,再把文件导入到数据库中. 读取Excel文件时,打开连接出错. 错误为:外部表不是预期的格式 解决:检查了一 ...

  8. 使用code标签获得类似代码段的效果

    几乎所有的浏览器都支持 code标签 code标签, 顾名思义,就是代码标签, imply tell browser, that 后面的部分是表示计算机代码. 因此, 浏览器可以根据自己的特点来显示这 ...

  9. 【AngularJS】—— 7 模块化

    AngularJS有几大特性,比如: 1 MVC 2 模块化 3 指令系统 4 双向数据绑定 那么本篇就来看看AngularJS的模块化. 首先先说一下为什么要实现模块化: 1 增加了模块的可重用性 ...

  10. nyoj 14 会场安排问题(贪心专题)java

    会场安排问题 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办.小刘的工 ...