tornado 排程

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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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 <[email protected]> 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()

  

时间: 2024-10-10 03:46:19

tornado 排程的相关文章

第十六章、例行性工作排程 (crontab)

1. 什么是例行性工作排程 1.1 Linux 工作排程的种类: at, crontab 1.2 Linux 上常见的例行性工作 2. 仅运行一次的工作排程 2.1 atd 的启动与 at 运行的方式: /etc/at.deny 2.2 实际运行单一工作排程: at, atq & atrm, batch 3. 循环运行的例行性工作排程 3.1 使用者的配置: /etc/cron.deny, crontab 3.2 系统的配置档: /etc/crontab 3.3 一些注意事项 4. 可唤醒停机期

Tornado 协程

同步异步I/O客户端 from tornado.httpclient import HTTPClient,AsyncHTTPClient def ssync_visit(): http_client = HTTPClient() response = http_client.fetch('www.baidu.com') # 阻塞,直到网站请求完成 print(response.body) def hendle_response(response): print(response.body) de

linux例行性工作排程

1.例行性排程有两中方式: 1)每隔一定周期就要来办的事项,用crontab指令实现 2)突发性的,就是这次做完后,就没有了用at指令实现,不过这个需要atd服务的支持 2.linux常见的例行性任务有: 1)进行登录档的轮替:linux会将系统所发生的各种信息都记录下来,这就是登录档,随着系统的运行这些登录档会越来越大,导致系统读写效能下降,因此就需要将这些数据按时间的新旧分别存放,这就是登录档的轮替任务 2)登录文件分析:如果系统发生了软件问题,硬件错误,资源安全问题等,绝大部分的错误都会被

apscheduler 排程

https://apscheduler.readthedocs.org/en/v2.1.2/cronschedule.html 参数 说明 year 4位年 month 月份1-12 day 日:1-31 week ISO周数:1~53 day_of_week 周日序, 0~6 或者 mon,tue,wed,thu,fri,sat,sun hour 小时: 0~23 minute 分钟:0~59 second 秒:0~59     dow注意,第一天是周一,不是周日.以下为以上参数的有效表达:

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/ Linux Kernel 排程機制介紹 Linux Kernel 排程機制介紹 [email protected] by loda. 2011/12/2 多核心架構儼然是目前智慧型手機方案的新趨勢,隨著省電與效能上的考量,多核心的架構各家方案也都有所差異.為能讓同一個Linux Kernel在不同效

Linux例行性工作排程 (crontab)

crontab是Unix和Linux用于设置周期性被执行的指令,是互联网很常用的技术,很多任务都会设置在crontab循环执行,如果不使用crontab,那么任务就是常驻程序,这对你的程序要求比较高,一个要求你的程序是24X7小时不宕机,一个是要求你的调度程序比较可靠,实际工作中,90%的程序都没有必要花这么多时间和精力去解决上面的两个问题的,只需要写好自己的业务逻辑,通过crond这个工业级程序去调度就行了,crond的可靠性,健壮性,是毫无疑问的. 使用者的配置 使用者想要创建循环型工作排程

ubuntu 使用crontab实现工作排程

Cron是Linux系统中最有用的工具之一,cron作业是在指定时间到来时被调度执行的作业. 最常见的自动化系统管理和自动维护工作,比如每天发出的按计划完成了备份的通知,或者是按计划定时清理/tmp/目录的通知.还有很多Web应用程序也需要执行定时作业.到时间吃饭了发送一封邮件通知你可以吃饭了,通知你比赛开始了等等 Linux 上常见的例行性工作 1.进行登录档的轮替 (log rotate): Linux 会主动的将系统所发生的各种资讯都记录下来,这就是登录档 . 由於系统会一直记录登录资讯,

例行性工作排程 (crontab)

1. 什么是例行性工作排程 1.1 Linux 工作排程的种类: at, crontab 1.2 Linux 上常见的例行性工作2. 仅运行一次的工作排程 2.1 atd 的启动与 at 运行的方式: /etc/at.deny 2.2 实际运行单一工作排程: at, atq & atrm, batch3. 循环运行的例行性工作排程 3.1 使用者的配置: /etc/cron.deny, crontab 3.2 系统的配置档: /etc/crontab 3.3 一些注意事项4. 可唤醒停机期间的工

基于hadoop (map/reduce)的大规模分布式并行计算生产排程系统的设计

map/reduce是大数据处理的技术,它的思路是把大规模数据分成一个个小数据块,每个数据块由一个map任务来处理,处理的中间结果汇总到reduce,最后生成最终的处理结果,这个处理和汇总的过程是可以反复多次的,也就是map-reduce-map-reduce 基于map/reduce的思路,我们可以设计基于hadoop(map/reduce)的大规模分布式并行计算生产排程系统,怎么样把大数据处理变成大规模分布式并行计算呢,就是我们不切分数据,每个map任务的数据都是相同的,每个map任务对排程