Message Boards Message Boards

GROUPS:

Problem with ScheduledTask timespec in Mathematica 12.0

Posted 2 years ago
3754 Views
|
4 Replies
|
1 Total Likes
|

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"]

enter image description here

Check the list of tasks: enter image description here

Remove the task:

enter image description here

Confirm the task has been removed: enter image description here

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"]

enter image description here

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

enter image description here

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

It looks as if the task has been scheduled: enter image description here

But this is highly misleading - there is nothing scheduled:

enter image description here

Nor does datelist format work:

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

enter image description here

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

Is anyone aware of a workaround?

4 Replies
Posted 2 years ago

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"]

Task Created Evaluation Result

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"
  ]

LocalSubmit output

Posted 2 years ago

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

https://www.wolfram.com/support/contact/email/?topic=feedback

Regards,

Neil

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

Regards,

Neil

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract