Written by

Senior Startups and Community Programs Manager at InterSystems Corporation
Question Evgeny Shvarov · Jun 19, 2023

How Can I use Job Command in Embedded Python?

How Job command can be used with Embedded Python code?

Product version: IRIS 2023.1

Comments

Eduard Lebedyuk · Jun 20, 2023

Do you want to job ObjectScript code? Write a wrapper class method and call it from embedded python.

0
Evgeny Shvarov  Jun 21, 2023 to Eduard Lebedyuk

Thanks Ed!

It is more that I convert ObjectScript to Python and it get stuck on Job command. Thought of something universal for such cases.

0
Alex Woodhead · Jun 21, 2023

Hi Evgeny,

The following is a tool System Management Specialists may use.

You can achieve Jobbing and also running arbitrary ObjectScript code by employing RunLegacyTask.

For example run arbitrary code:

USER>zw ^ABC

USER>D $SYSTEM.Python.Shell()
 
Python 3.9.5 (default, Mar 14 2023, 06:58:44) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.
>>> myjob=iris.cls("%SYS.Task.RunLegacyTask")._New()

>>> myjob.ExecuteCode="Set ^ABC=""123"""

>>> res=myjob.OnTask()

>>> res
1
>>> quit()

USER>zw ^ABC
^ABC=123

For example Jobbing a Routine.

Routine (Test.mac) source code:

TestSet ^ABC=345Quit

Use legacy Task to Job it off:

USER>zw ^ABC
^ABC=123
 
USER>D $SYSTEM.Python.Shell()
 
Python 3.9.5 (default, Mar 14 2023, 06:58:44) [MSC v.1927 64 bit (AMD64)] on win32
Type quit() or Ctrl-D to exit this shell.

>>> myjob=iris.cls("%SYS.Task.RunLegacyTask")._New()
>>> myjob.ExecuteCode="Job Test^Test"
>>> res=myjob.OnTask()
>>> res
1
>>> quit()
 
USER>zw ^ABC
^ABC=345

The status result can be useful to understand problems.

For example the Routine line label "Test" was miss-typed as "TEST"

>>> myjob=iris.cls("%SYS.Task.RunLegacyTask")._New()
>>> myjob.ExecuteCode="Job TEST^Test"
>>> res=myjob.OnTask()
>>> iris.cls("%SYSTEM.Status").DisplayError(res)
 
ERROR #5001: <NOLINE>zexecuteCode+3^%SYS.Task.RunLegacyTask.11

Enjoy IRIS. No limits :)

0
James MacKeith · Jun 21, 2023

Take a look at the WorkQueue Manager which also allows for coordination. 

workQueue =iris.cls("%SYSTEM.WorkMgr")._New()

status = workQueue.Queue("..PythonClassMethodToBeJobbed")

[Note routines require function [parentheses] not just a plain label - so for Alex's example below will need Test()]

0