Beispiel #1
0
        return self.add_job(timing_publish_deco(func), trigger, args, kwargs, id, name,
                            misfire_grace_time, coalesce, max_instances,
                            next_run_time, jobstore, executor,
                            replace_existing, **trigger_args)


fsdf_background_scheduler = FsdfBackgroundScheduler(timezone=frame_config.TIMEZONE)

if __name__ == '__main__':
    # 定时运行消费演示
    import datetime
    from function_scheduling_distributed_framework import task_deco, BrokerEnum, fsdf_background_scheduler, timing_publish_deco


    @task_deco('queue_test_666', broker_kind=BrokerEnum.LOCAL_PYTHON_QUEUE)
    def consume_func(x, y):
        print(f'{x} + {y} = {x + y}')


    if __name__ == '__main__':
        fsdf_background_scheduler.add_job(timing_publish_deco(consume_func), 'interval', id='3_second_job', seconds=3, kwargs={"x": 5, "y": 6})  # 每隔3秒发布一次任务,自然就能每隔3秒消费一次任务了。
        fsdf_background_scheduler.add_job(timing_publish_deco(consume_func), 'date', run_date=datetime.datetime(2020, 7, 24, 13, 53, 6), args=(5, 6,))  # 定时,只执行一次
        fsdf_background_scheduler.add_timing_publish_job(consume_func, 'cron', day_of_week='*', hour=14, minute=51, second=20, args=(5, 6,))  # 定时,每天的11点32分20秒都执行一次。

        # 启动定时
        fsdf_background_scheduler.start()

        # 启动消费
        consume_func.consume()

Beispiel #2
0
from function_scheduling_distributed_framework import fsdf_background_scheduler
from test_frame.car_home_crawler_sample.car_home_consumer import crawl_list_page, crawl_detail_page

crawl_list_page.clear()  # 清空列表页
crawl_detail_page.clear()  # 清空详情页

# # 推送列表页首页,同时设置翻页为True
crawl_list_page.push('news', 1, do_page_turning=True)  # 新闻
crawl_list_page.push('advice', page=1, do_page_turning=True)  # 导购
crawl_list_page.push(news_type='drive', page=1, do_page_turning=True)  # 驾驶评测

## 每隔60秒发布第一页任务,一直获取最新的新闻。
for news_typex in ['news', 'advice',
                   'drive']:  # 定时任务,语法入参是apscheduler包相同。每隔120秒查询一次首页更新,这个可以不要。
    fsdf_background_scheduler.add_timing_publish_job(crawl_list_page,
                                                     'interval',
                                                     seconds=120,
                                                     kwargs={
                                                         "news_type":
                                                         news_typex,
                                                         "page": 1
                                                     })
fsdf_background_scheduler.start()  # 启动首页查询有没有新的新闻的定时发布任务