# SessionSubmit with ScheduledTask

I am trying to learn about ScheduledTask and SessionSubmit so that I can have calculations that run regularly in the background at set times. It seems that according to the documentation for ScheduledTask you should be able to have something of the form

ScheduledTask[task,{start,timespec}]


Where start is the time a task should begin executing and timespec can be a DateObject[patt]. Given that, I tried the following simple example:

x=0
obj = SessionSubmit[ScheduledTask[x += 1, {Today, DateObject[{_, _, Monday | Tuesday | Wednesday | Thursday | Sunday, 21}]}]]


That code give me the error shown below.

I would expect the above code to add 1 to x at 9PM every Monday, Tuesday, Wednesday, Thursday, and Sunday.

The end goal would be to setup code that runs at a set time a few days each week. I'm thinking if I can understand how to make this simple code work, it should be simple enough to expand to a more complicated case.

## 1 Answer

I ended up moving the days into the expression to be evaluated to act as a filter in a daily evaluation.

x=0;
obj = SessionSubmit[ScheduledTask[If[
MemberQ[{Monday, Tuesday, Wednesday, Thursday, Sunday},
DayName[]], x += 1], "Daily"]]


You can use a start date and time with "Daily" (also an end date if desired). I am not sure if "Daily" means 24 hours from the start date, but if not Quantity[24,"Hours"] can likely be used. For example, the following will complete the first evaluation at 11h21 (not 11h20 it seems!) today and continue evaluating every minute. Note that I added Friday to the list of days to ensure we see some action.

obj = SessionSubmit[
ScheduledTask[
If[MemberQ[{Monday, Tuesday, Wednesday, Friday, Sunday},
DayName[]], x += 1], {DateObject[{2022, 8, 5, 11, 20, 0}],
Quantity[1, "Minutes"]}]]

• That solves the issue of running on the correct days. Is it possible to have it run at a specific time each day? I think this would just run again each day at the time I originally run the code.
– Nate
Aug 5, 2022 at 14:18
• I edited the post. Note that you can use obj["Schedule"] to see a summary of the task schedule. Aug 5, 2022 at 15:13