Article
· Dec 19, 2020 1m read

Schedule tasks with one line using iris-cron-task

Hi, folks!

Sometimes I need to schedule a task programmatically.

And in 99% I need having some class method be periodically called.

And I want to have the schedule be started by one line. As a job in crontab.

I decided to introduce such a module with iris-cron-task module.

See the details below!

Install the module with:

USER>zpm "install iris-cron-task"

And then you'll be able to schedule tasks with one line. 

E.g. if I want the following command

set ^A($I(^A))=$H

be started every minute I can call the following:

zw ##class(dc.cron.task).Start("Task name","* * * * *","set ^A($I(^A))=$H",1,.taskid)

this will create a task with taskid which will run every minute.

When you don't need the task any more you can delete it with:

zw ##class(dc.cron.task).Kill(taskid)

I supported only a few cron settings, like every minute:

* * * * *

Every hour:

0 * * * *

And every day in a certain hour:

0 0 * * *

You could find useful the cronmaker site to get the cron expression for any schedule you need.

Thanks to @Lorenzo Scalese for introducing support for an arbitrary cron expression. 

PR are welcome if you need more!

Hope you like it, any feedback is appreciated!

Discussion (8)1
Log in or sign up to continue