iris-cron-task
Class to setup tasks running at schedule with cron expression.
The cron expression could be taken from cronmaker site
Thanks to Lorenzo’s Skaleze PR this works with any cron expression.
Installation with ZPM
USER>zpm “install iris-cron-task”
Installaton with importing class
Import the class into your system.
testing with docker and collaboration
Clone/git pull the repo into any local directory
$ git clone https://github.com/evshvarov/iris-cron-task.git
Open the terminal in this directory and run:
$ docker-compose build
- Run the IRIS container with your project:
$ docker-compose up -d
Usage
Open IRIS terminal:
$ docker-compose exec iris iris session iris
USER>
Run "set ^A($I(^A))=$H"
every minute:
USER>zw ##class(dc.cron.task).Start("IRIS cron task name","* * * * *","s ^A($I(^A))=$H",1,.taskId)
taskId contains the id of the task created:
USER>w taskId
1000
It will store in a global ^A the something like the following:
USER>zw ^A
^A=6
^A(1)="65732,54180"
^A(2)="65732,54240"
^A(3)="65732,54300"
^A(4)="65732,54360"
^A(5)="65732,54420"
^A(6)="65732,54480"
Run "set ^B($I(^B))=$H"
every hour:
USER>zw ##class(dc.cron.task).Start("IRIS cron task name","0 * * * *","s ^B($I(^B))=$H",1,.taskId)
Run "set ^A($I(^A))=$H"
every day at midnight:
USER>zw ##class(dc.cron.task).Start("IRIS cron task name","0 0 * * *","s ^C($I(^C))=$H",1,.taskId)
And you can delete the task when you don’t need it anymore.
USER>zw ##class(dc.cron.task).Kill(taskId)
Usage with python
You can use the python script to start the task from the command line.
from iris_cron import Task
if name == 'main':
# in objectscript
tid = Task.create_objectscript_task('test', '0 0 1 * * *','set ^test($h) = "test"', run_now=True)
print(tid)
# in python
task = """
import time
import iris
gref = iris.gref('testpython')
gref['time'] = time.time()
"""
tid = Task.create_python_task('test', '0 0 1 * *', task, run_now=True)
print(tid)
# get tasks
tasks = Task.get_tasks()
print(tasks)
CronMaker syntax
CronMaker syntax is also supported by using StartByCronMakerExpression
method.
Example, run every Monday and Tuesday at 2:00 pm :
Set sc = ##class(dc.cron.task).StartByCronMakerExpression("The Task Name","0 0 14 ? * MON,TUE *","set ^A($I(^A))=$H",,.tid)
or you can call method Start because it uses StartByCronMakerExpression inside now.
Set sc = ##class(dc.cron.task).Start("The Task Name","0 0 14 ? * MON,TUE *","set ^A($I(^A))=$H",,.tid)
Collaboration
You are very welcome to collaborate and make changes.
Fork the repository and send Pull Request.
Below I describe how to make changes in ObjectScript part:
Prerequisites
Make sure you have git and Docker desktop installed.
This repository is ready to code in VSCode with ObjectScript plugin.
Install VSCode, Docker and ObjectScript plugin and open the folder in VSCode.
Open /src/cls/PackageSample/ObjectScript.cls class and try to make changes - it will be compiled in running IRIS docker container.
Feel free to delete PackageSample folder and place your ObjectScript classes in a form
/src/Package/Classname.cls
Read more about folder setup for InterSystems ObjectScript
The script in Installer.cls will import everything you place under /src into IRIS.
What’s inside the repository
Dockerfile
The simplest dockerfile which starts IRIS and imports code from /src folder into it.
Use the related docker-compose.yml to easily setup additional parametes like port number and where you map keys and host folders.
.vscode/settings.json
Settings file to let you immedietly code in VSCode with VSCode ObjectScript plugin)
.vscode/launch.json
Config file if you want to debug with VSCode ObjectScript
Read about all the files in this artilce