This page gives a good introduction to Plan. If you do not have Plan installed, check out Installation section.

A Minimal Example

A simple usage looks like this:

from plan import Plan

cron = Plan()

cron.command('ls /tmp', every='1.day', at='12:00')
cron.command('pwd', every='2.month')
cron.command('date', every='weekend')

if __name__ == "__main__":

Just save it as schedule.py (or whatever you want) and run it with your Python interpreter. Make sure to not name it plan.py becaure it would conflict with Plan itself.

Now we do not run with one explicit run_type, default run_type check will be used, you should see your cron syntax jobs in the output of terminal:

# Begin Plan generated jobs for: main
0 12 * * * ls /tmp
0 0 1 1,3,5,7,9,11 * pwd
0 0 * * 6,0 date
# End Plan generated jobs for: main


So what did the above code do?

  1. First we imported the Plan class. An instance of this class will be one group of cron jobs.
  2. Next we create an instance of this class. We are not passing any arguments here, though, the first argument is the name of this group of cron jobs. In our case, we have the default name ‘main’ here. For more information have a look at the Plan Definition documentation.
  3. We then use the command() to register three command jobs on this Plan object.
  4. Finally we run this Plan object and check your cron syntax jobs or write it to your crontab.
当前网页内容, 由 大妈 ZoomQuiet 使用工具: ScrapBook :: Firefox Extension 人工从互联网中收集并分享;
若有不妥, 欢迎评注提醒:


订阅 substack 体验古早写作:

点击注册~> 获得 100$ 体验券: DigitalOcean Referral Badge

关注公众号, 持续获得相关各种嗯哼:


关于 ~ DebugUself with DAMA ;-)
公安备案号: 44049002000656 ...::