Dynamic parameters

Skip to first unread message

Pablo Maldonado

Jun 26, 2019, 12:15:06 PM6/26/19
to schedulix

How could they return in a parameter the name of the day in which the job was executed.
In other words, if it was executed on Monday or Tuesday, return the name of the day (attached image).

Thank you

Pablo Maldonado

Dieter Stubler

Jun 27, 2019, 2:02:12 AM6/27/19
to schedulix
Hi Pablo,

not sure what you want to achieve.
Do you want to have the weekday information available while running the job or after it has been executed for analytics ?
If you want to decide in your job what do to depending on the weekday, I would regard that as a poor design.
This would move scheduling functionality into your jobs code which should be avoided because it harms transparency and maintainability.
With schedulix 2.9 you can enable/disable children in a batch based on an interval allowing to select weekdays to execute.

You can use system defined parameters like $SUBMITTIME giving you a string in format YYYYMMDDHHmmss.
There is no weekday function, so you have to use date arithmetics on the timestamp to get the weekday.
What you can do, is to write this once as a utility job called SETSUBMITWEEKDAY which gets the $SUBMITTIME as a parameter and sets a RESULT parameter SUBMITWEEKDAY.
Run this job as first job in batches you need this information.
On the top level batch of those batches you can then create a child reference parameter to the SUBMITWEEKDAY result of the SETSUBMITWEEKDAY.
Now you can use the $SUBMITWEEKDAY in any command line of the other jobs in your batches.

Here is an example of a python script setting the weekday (setsubmitweekday.py):

import sys
import os
from datetime import datetime

weekday = datetime.strptime(sys.argv[1], '%Y%m%d%H%M%S').strftime('%A')

cmd = "sdms-set_variable" + \
        " -h '" + os.getenv('SDMSHOST') + "'" + \
        " -p "  + os.getenv('SDMSPORT') + \
        " -j "  + os.getenv('JOBID') + \
        " -k "  + os.getenv('KEY') + \
        " SUBMITWEEKDAY " + weekday

print "cmd = " + cmd

The script assumes Env. Mapping as defined for the Scope EXAMPLES to provide SDMSHOST, SDMSPORT, JOBID and KEY to the jobs environment variables.
The run program would look like 'python setsubmitweekday.py $SUBMITTIME'


Pablo Maldonado

Jun 27, 2019, 10:36:13 AM6/27/19
to schedulix
Hello Dieter,

What I want to achieve is:

JOB1 runs every Monday
JOB2 runs all 15 of the month, but if it is Monday it must run after JOB1

then it occurred to me to export from JOB1 on the day of the month and if it is 15, it triggers JOB2.
And JOB2 schedule it to run every day 15 except it's Monday, since I shot it from JOB1.

The other thing that occurred to me and I think it worked, is to create an "Exit Satete Definition", "Exit State Mappings" and "Exit State Profile" where if the script returns 0 it is not 15 of the month, if it returns 1 is 15 of the month and out of this is error.

Pablo Maldonado

Dieter Stubler

Jun 28, 2019, 3:42:36 AM6/28/19
to schedulix
Hi Pablo,

seems to be a good solution to your task.
In 2.9 you also could utilize the new external dependency feature to achieve that.

You would do it like that:
Define an EXTERNAL dependency of JOB2 dependent on JOB1, with EXPIRE 1 day and unresolved handling IGNORE.
Now you have only to make sure that JOB1 will be submitted earlier than JOB2. Let's say JOB 1 every Monday 01:00 and JOB2 every 15th 02:00.
So if it is not Monday JOB2 will not find an instance of JOB1 younger than 1 day and will ignore its dependency and just runs.
If its Monday JOB2 will find the prior submitted JOB1 and resolves its dependency on JOB1 and waits until JOB1 is done.
Be aware that cancelling JOB1 will handled as it was never submitted, so JOB2 will start running.


Pablo Maldonado

Jun 28, 2019, 10:53:49 AM6/28/19
to schedulix
Hi Dieter,

Great, since I have version 2.9, I'm going to try it.

Pablo Maldonado
Reply all
Reply to author
0 new messages