Schedule Jobs

We can schedule to run jobs at specified time with specified frequencies.

Please note that if a scheduled job calls a shared table, the shared table needs to be defined in the startup script (startup.dos). If a scheduled job calls a function in a plugin, the plugin needs to be loaded in the startup script.

Related functions/commands:

Schedule to run a function:

$ def f():1+2;
$ scheduleJob(`daily, "Daily Job", f, 17:23m, 2018.01.01, 2018.12.31, 'D');
$ daily
$ scheduleJob(`weekly, "Weekly Job", f, 17:30m, 2018.01.01, 2018.12.31, 'W', 2);
$ weekly

Schedule to run a script:

$ scheduleJob(`monthly, "Monthly Job", run{"C:\DolphinDB\script\monthlyJob.dos"}, 17:23m, 2018.01.01, 2018.12.31, 'M', 1);
$ monthly

Here we use a partial application run{<script>} as this parameter needs to be a function with no arguments.

$ getJobMessage(`daily);
$ 2018-02-08 17:23:27.166296 Start the job [daily]: Daily Job 1
$ 2018-02-08 17:23:27.167303 The job is done.

$ getJobReturn(`daily);
$ 3

We can schedule to run the same job multiple times a day:

$ scheduleJob(`Trading, "Generate Trading Tickets", run{"C:\DolphinDB\script\TradingTickets.dos"}, [09:25m, 12:00m, 02:00m, 15:50m], 2018.01.01, 2018.12.31, 'D');
$ Trading

In this case, each time this scheduled job is executed, the job ID is different. The job IDs for the first day is “Trading”, “Trading000”, “Trading001”, “Trading002” for the first day, and “Trading003”, “Trading004”, “Trading005”, “Trading006” for the second day, etc.

We can schedule to run the same job multiple times a day for the working days in a week:

$ scheduleJob(`PnL, "Calculate Profit & Loss", run{"C:\DolphinDB\script\PnL.dos"}, [12:00m, 02:00m, 14:50m], 2018.01.01, 2018.12.31, 'W', [2,3,4,5,6]);
$ PnL
$ getScheduledJobs();

userId

jobId

jobDesc

startDate

endDate

frequency

scheduleTime

days

root

PnL

Calculate Profit &…

2018.01.01

2018.12.31

W

12:00m 02:00m 14:50m

2 3 4 5 6

root

TradingTicket

Generate Trading T…

2018.01.01

2018.12.31

W

09:25m 12:00m 02:0…

2 3 4 5 6

root

daily

Daily Job

2018.01.01

2018.12.31

D

17:23m

root

monthly

Monthly Job

2018.01.01

2018.12.31

M

17:23m

1

root

weekly

Weekly Job

2018.01.01

2018.12.31

W

17:30m

2

$ deleteScheduledJob(`monthly)
$ deleteScheduledJob(`weekly)
$ deleteScheduledJob(`daily);

$ getScheduledJobs();

userId

jobId

jobDesc

startDate

endDate

frequency

scheduleTime

days

root

PnL

Calculate Profit &…

2018.01.01

2018.12.31

W

12:00m 02:00m 14:50m

2 3 4 5 6

root

TradingTicket

Generate Trading T…

2018.01.01

2018.12.31

W

09:25m 12:00m 02:0…

2 3 4 5 6