pythoncronexpressionapscheduler

create apscheduler job trigger from cron expression


I'm trying to run some scheduled jobs using cron expressions in python. I'm new to python and I've already worked with quartz scheduler in java to achieve almost the same thing. Right now, I am trying to work with apscheduler in python. I know that it is possible to do this using

crontrig = CronTrigger(minute='*', second = '*');

But, I was working with cron expressions (like "0/5 * * * * *") and I would like to know if there is anything which could directly parse the expression and generate a CronTrigger.


Solution

  • Given that APScheduler supports a slightly different set of fields, it's not immediately obvious how those expressions would map to CronTrigger's arguments.

    I should also point out that the preferred method of scheduling jobs does not involve directly instantiating triggers, but instead giving the arguments to add_job() instead.

    If you want to do that yourself, you could simply split the expression and map the elements to whichever trigger arguments you want.