TaskObject

TaskObject[spec]

is an object that represents a background task.

Details

  • Tasks are created by functions such as SessionSubmit, LocalSubmit and CloudSubmit.
  • TaskObject[spec][prop] gives the value of a property of a task.
  • Properties of all tasks include:
  • "EvaluationExpression"expression to evaluate when the task is executed
    "EvaluationResult"result of evaluating the task expression
    "EventData"the most recent values of all handler functions keys
    "HandlerFunctions"handlers specified by the HandlerFunctions option
    "HandlerFunctionsKeys"handler functions keys specified by HandlerFunctionsKeys
    "TaskEnvironment""Session", "Local", "Cloud" or "External"
    "TaskStatus"status of the task ("Running", "Waiting", etc.)
    "TaskType"type of task ("Immediate", "Scheduled", etc.)
    "TaskUUID"unique task identifier
  • The expression to evaluate is returned wrapped in Hold.
  • The most recent values of handler functions keys given by "EventData" are returned as an association. If a particular key has not yet been set, it is returned as Missing[].
  • Scheduled tasks have the following additional properties:
  • "Schedule"task schedule specification
    "RunInterval"interval between task runs
    "PreviousRunCount"number of times the task has already run
    "RemainingRunCount"number of times the task still has to run
    "TotalRunCount"total number of times the task is scheduled to run
  • A list of all available properties of a task object obj can be obtained using obj["Properties"].
  • Possible task statuses include:
  • "Waiting"task is waiting to run
    "Running"task expression is currently being evaluated
    "Finished"task is finished and will not repeat
    "Suspended"task has been suspended
    "Removed"task has been removed
  • Possible task types include: "Immediate", "Asynchronous", "Scheduled" and "Continuous".
  • Normal[obj] gives a representation of a TaskObject as an association.

Examples

Basic Examples  (4)

Run a task in the current session:

In[1]:=
Click for copyable input
Out[1]=

Convert a TaskObject to Association:

In[2]:=
Click for copyable input
Out[2]=

Create a task:

In[1]:=
Click for copyable input
Out[1]=

Look up a task's UUID:

In[2]:=
Click for copyable input
Out[2]=

Look up available task properties:

In[3]:=
Click for copyable input
Out[3]=

Get an Association representing the task:

In[4]:=
Click for copyable input
Out[4]=
In[5]:=
Click for copyable input
Out[5]=

Run a task in a separate kernel:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

Run a cloud-based task:

In[1]:=
Click for copyable input
Out[1]=
In[2]:=
Click for copyable input
Out[2]=

See Also

Tasks  $CurrentTask  TaskSuspend  TaskResume  TaskRemove  TaskExecute  TaskWait  SessionSubmit  LocalSubmit  CloudSubmit

Introduced in 2017
(11.2)