Problem with ScheduledTask timespec in Mathematica 12.0

I am having a problem using the timespec specified in the Wolfram documentation for ScheduledTask. I believe the issue has been extant since v11.

Let’s take an example from the documentation:

obj = LocalSubmit[ScheduledTask[DateString[], "Hourly"], 
  HandlerFunctions -> <|"ResultReceived" -> Print|>, 
  HandlerFunctionsKeys -> "EvaluationResult"]

Check the list of tasks:

Remove the task:

Confirm the task has been removed:

5QzhX.png

Now specify the same scheduled task, with a starting date/time. This works ok:

obj = LocalSubmit[ScheduledTask[DateString[], {Now, "Hourly"}], 
  HandlerFunctions -> <|"ResultReceived" -> Print|>, 
  HandlerFunctionsKeys -> "EvaluationResult"]

But when we try to specify a start date, it fails:

obj = LocalSubmit[ScheduledTask[DateString[], {Now, "Hourly"}], 
  HandlerFunctions -> <|"ResultReceived" -> Print|>, 
  HandlerFunctionsKeys -> "EvaluationResult"]

It looks as if the task has been scheduled:

But this is highly misleading - there is nothing scheduled:

Nor does datelist format work:

obj = LocalSubmit[
  ScheduledTask[DateString[], {{2019, 12, 23, 9, 35, 0}, "Hourly"}], 
  HandlerFunctions -> <|"ResultReceived" -> Print|>, 
  HandlerFunctionsKeys -> "EvaluationResult"]

wJ6NZ.png

I have made numerous other attempts to get ScheduledTask to work as per the documentation, without success.

Is anyone aware of a workaround?

I was able to replicate your issue, and think the problem is LocalSubmit, which initiates a new subkernel (which may be your intention). If you switch to SessionSubmit, you should be ok.

startTime = TimeObject[{18, 20, 0}];
endTime = TimeObject[{18, 22, 0}];
sessionStart = DateObject[Today, startTime];
sessionEnd = DateObject[Today, endTime];

obj = SessionSubmit[ScheduledTask[DateString[], {sessionStart, Quantity[1, "Minutes"], sessionEnd}],
HandlerFunctions -> <|"ResultReceived" -> Print|>,
HandlerFunctionsKeys -> "EvaluationResult"]

I’m guessing LocalSubmit needs specific HandlerFunctions and/or HandlerFunctionsKeys to work properly, or perhaps some other kernel initialization.

Update: I’ve been able to get LocalSubmit work in the manner you expected. I added an end to the timespec, but it also works without it.

obj = LocalSubmit[
  ScheduledTask[
   DateObject[], {Now, Quantity[1, "Minutes"], 
    Now + Quantity[2, "Minutes"]}],
  HandlerFunctions -> <|"ResultReceived" -> Print|>,
  HandlerFunctionsKeys -> "EvaluationResult"
  ]

As I pointed out in the original post, ScheduledTask works if you use Now in the timesec, but not if you use a date in date object or datelist format.

So that issue remains unresolved and ScheduledTask does not work as advertised with LocalSubmit.

However, it does appear to work with SessionSubmit, which is fine as a workaround, although it would be nice if WR would fix this problem in an upcoming release.

Jonathan,

Please report this to support. They are very responsive to bug reports.

Either send email to support@wolfram.com or go to

Regards,

Neil

I have reported related but different issues with Scheduled Tasks so it is best to report all of them.

Regards,

Neil