({{, (RefLink[ScheduledTask, paclet:ref/ScheduledTask])[expr,timespec] 
represents a scheduled task to be evaluated on the schedule defined by timespec.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[CloudDeploy, paclet:ref/CloudDeploy])[ScheduledTask[…]] deploys a scheduled task to be executed in the cloud.

(RefLink[SessionSubmit, paclet:ref/SessionSubmit]), (RefLink[LocalSubmit, paclet:ref/LocalSubmit]) and (RefLink[CloudSubmit, paclet:ref/CloudSubmit]) submit scheduled tasks for background evaluation in the current session, on the local system or in the cloud.

Submitted tasks can be controlled using (RefLink[TaskSuspend, paclet:ref/TaskSuspend]), (RefLink[TaskResume, paclet:ref/TaskResume]), etc.

The argument expr can be the Wolfram Language code to be evaluated, or a (RefLink[CloudObject, paclet:ref/CloudObject]) or (RefLink[File, paclet:ref/File]) containing Wolfram Language input.

The following time period specification can be given:

The following timespec specifications can be given:

The following specifications can be given to limit when the task can be run:

start and end parameters should be given as a (RefLink[DateObject, paclet:ref/DateObject]) or other time specification.

Additional timespec specifications can be given:

In (RefLink[DateObject, paclet:ref/DateObject])[patt], the pattern patt has the form {y,m,d,h,m,s}, where later elements can be dropped, and where each element can be a literal integer, a choice of integers of the form (Subscript[n, 1])|(Subscript[n, 2])|…, or _ representing any possible value. For the day element, literal days can be replaced by symbols indicating a day of the week, such as (RefLink[Monday, paclet:ref/Monday]).

The following options can be given:

For purposes of (RefLink[NotificationFunction, paclet:ref/NotificationFunction]), a task is considered to have failed if its output is (RefLink[$Failed, paclet:ref/$Failed]) or a (RefLink[Failure, paclet:ref/Failure]) object.

In the cloud, the precise times at which scheduled tasks are run are typically determined by load-balancing requirements.

The minimum time between repetitions of a task in the cloud is determined by cloud configuration and policies and will typically be a certain fraction of an hour.

OpenersPrimaryExamplesSection(Spacer1)Examples  (9)

OpenersExampleSection0(Spacer1)Basic Examples  (6)

Create a scheduled task in a local session:

obj=SessionSubmit[ScheduledTask[Print[DateString[]],{1,3}]]

Create a scheduled cloud task that logs the date and temperature hourly:

obj=CloudDeploy[ScheduledTask[{Now,AirTemperatureData[]},"Hourly"]]

Delete the task:

TaskRemove[obj]

Create a scheduled task on a separate kernel:

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

Delete the task:

TaskRemove[obj]

Create a scheduled cloud task that emails the task owner the temperature daily for the next month:

obj=CloudSubmit[ScheduledTask[SendMail[<|"To"->$WolframID,"Subject"->DateString[],"Body"->AirTemperatureData[]|>],{"Daily",DatePlus[DateObject["now"], (QuantityUnit)]}]]

Delete the task:

TaskRemove[obj]

Create a scheduled cloud task that logs the opening price of a financial instrument on weekdays:

obj=CloudDeploy[ScheduledTask[{Now,FinancialData["QQQ","Open"]},"* 10 * * 1,2,3,4,5"]]

Delete the task:

TaskRemove[obj]

Create a scheduled cloud task that updates a time stamp in the cloud once a day:

time=DateList[];

var=CloudSave[time];

obj=With[{co=var},CloudSubmit[ScheduledTask[time=DateList[];CloudSave[time,co],"Daily"]]
]

Get the current time stamp:

CloudGet[var]

Run the scheduled task cloud object using (RefLink[TaskExecute, paclet:ref/TaskExecute]):

TaskExecute[obj]

The time stamp has been updated:

CloudGet[var]

Delete the task:

TaskRemove[obj];

OpenersExampleSection1(Spacer1)Generalizations & Extensions  (1)

Use (RefLink[TaskSuspend, paclet:ref/TaskSuspend]) to suspend scheduled executions of a cloud-scheduled task:

obj=CloudSubmit[ScheduledTask[TimeObject[],"Daily"]]

TaskSuspend[obj]

Delete the task:

TaskRemove[obj]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)NotificationFunction  (1)

Notifications allow indicated parties to receive status messages on task evaluation. Deploy a task that notifies multiple parties after every run:

co=CloudSubmit[ScheduledTask[{Now,AirTemperatureData[]},"Daily",
NotificationFunction->{{$WolframID,"a@b.com"}->All}
]]

Trigger the task to run asynchronously:

TaskExecute[co]

Trigger the task to run again:

TaskExecute[co]

Delete the task:

TaskRemove[co]

OpenersExampleSection3(Spacer1)Applications  (1)

Create an application that sends an email alert based on a scheduled task:

CheckForFullMoon[]:=If[MoonPhase[Tomorrow]>0.99,SendLunarAlertMail[]]

SendLunarAlertMail[]:=SendMail[<|"To"->$WolframID,"Subject"->"Alert: Full Moon","Body"->{"There will be a full moon tomorrow: "<>DateString[Tomorrow],"\n\n",MoonPhase[Tomorrow,"Icon"],"\n\n","http://www.wolframalpha.com/input/?i=moon+phase"}|>]

Make a scheduled task that evaluates at 18:00 every day and checks tomorrow's moon phase:

obj=CloudSubmit[ScheduledTask[CheckForFullMoon[],DateObject[{_,_,_,18}]]]

Delete the task:

TaskRemove[obj]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[AutoRefreshed, paclet:ref/AutoRefreshed])  ▪  (RefLink[Delayed, paclet:ref/Delayed])  ▪  (RefLink[TaskSuspend, paclet:ref/TaskSuspend])  ▪  (RefLink[TaskExecute, paclet:ref/TaskExecute])  ▪  (RefLink[TaskRemove, paclet:ref/TaskRemove])  ▪  (RefLink[DocumentGenerator, paclet:ref/DocumentGenerator])  ▪  (RefLink[Once, paclet:ref/Once])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Using Connected Devices, paclet:guide/UsingConnectedDevices])}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[Background & Scheduled Tasks, paclet:guide/BackgroundAndScheduledTasks])}, {▪(RefLinkPlain[Automated Reports, paclet:guide/AutomatedReports])}, {▪(RefLinkPlain[Cloud Functions & Deployment, paclet:guide/CloudFunctionsAndDeployment])}, {▪(RefLinkPlain[Accessing External Services & APIs, paclet:guide/AccessingExternalServicesAndAPIs])}})}})