项目作者: primary-student

项目描述 :
This is a python testing framework used to verify whether the scheduled task will execute as expected at the scheduled time.
高级语言:
项目地址: git://github.com/primary-student/scheduled_task_verification_framework.git
创建时间: 2021-02-01T04:53:49Z
项目社区:https://github.com/primary-student/scheduled_task_verification_framework

开源协议:Apache License 2.0

下载


scheduled_task_verification_framework

This is a python testing framework used to verify whether the scheduled task will execute as expected at the scheduled time.

It has been personally tested on centos7.

Please note that running the example will change the system time!
" class="reference-link">
Please note that running the example will change the system time!

Please execute the example in a test environment

" class="reference-link">
Please execute the example in a test environment

Usage

Way 1: Explicitly add decorators to your scheduled method. (See “Example\Example 1 Using decorator on task-func.py“ for the complete code)

  1. from apscheduler.schedulers.background import BackgroundScheduler
  2. from scheduled_task_verification_framework import scheduler_task_manager
  3. scheduler_task_manager_obj = scheduler_task_manager()
  4. @scheduler_task_manager_obj.is_cronTask(name = "monday",task_scheduled_run_at = now_is_monday)
  5. def task_on_every_monday():
  6. print("Running task [task_on_every_monday], %s" %strftime("%Y-%m-%d-%H_%M_%S", localtime()))
  7. scheduler = BackgroundScheduler()
  8. scheduler.add_job(task_on_every_monday, 'cron',day_of_week="mon", hour=1, minute=1)
  9. scheduler.start()
  10. scheduler_task_manager_obj.monitor(……)

Way 2: Create a new method with hook instead of the old scheduled method. (See “Example\Example 2 Run new task func instead of old.py“ for the complete code)

  1. from apscheduler.schedulers.background import BackgroundScheduler
  2. from scheduled_task_verification_framework import scheduler_task_manager
  3. scheduler_task_manager_obj = scheduler_task_manager()
  4. def task_on_every_monday():
  5. print("Running task [task_on_every_monday], %s" %strftime("%Y-%m-%d-%H_%M_%S", localtime()))
  6. new_task_on_every_monday = scheduler_task_manager_obj.is_cronTask(name = "monday",task_scheduled_run_at = now_is_monday)(task_on_every_monday)
  7. scheduler.add_job(new_task_on_every_monday, 'cron',day_of_week="mon", hour=1, minute=1)
  8. scheduler.start()
  9. scheduler_task_manager_obj.monitor(……)