ESE Routines > ESETask

# ESETask

The ESETask class represents ESE tasks. Each time a task is run, a new job is produced. Tasks represent algorithms and jobs represent the execution of an algorithm, with particular inputs, outputs and state. However, ESETask objects do provide the ability to specify input parameter values prior to being run.

## Methods

- ESETask::GetParameter
- ESETask::GetParameters
- ESETask::GetParent
- ESETask::Info
- ESETask::Run

## Examples

### Example 1

This example demonstrates the simplest form of how to connect to an ESE server, get a task and run it:

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Job = Task.Run( a = 1, b = 2 )

### Example 2

By default, both asynchronous and synchronous tasks are run synchronously. However, asynchronous tasks can be freed to run asynchronously via the ASYNCHRONOUS keyword to run:

Task = ESE.findTask( 'localhost', 'smooth_sailing' )

Job = Task.run( /ASYNCHRONOUS )

### Example 3

In this example, the task is run with the same values as in the first example, but the values are set on the task object, instead of in the "run" method.

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Task.a = 1

Task.b = 2

Job = Task.Run()

### Example 4

In this example the run method overrides the value of a set on the task object.

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Task.a = 1

Job = Task.Run( a = 9, b = 2 )

The task object retains a value of 1 for a, but the job is run with a value of 9. To continue:

PRINT, Task.a

PRINT, Job.a

prints out '1' and '9'.

### Example 5

This example sets one parameter on the task and then supplies values for the second parameter when the task is run. For all invocations, parameter 'a' will have a value of 1.

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Task.a = 1

FOR i = 0, 9 DO BEGIN

Job = Task.Run( b = i )

PRINT, 'Computation: ' + $

strtrim( Job.a, 2 ) + ' + ' + $

strtrim( Job.b, 2 ) + ' = ' + $

strtrim( Job.answer, 2 )

ENDFOR

## Properties

### PARAMETERNAME (IDLVariable, Set, Get)

The name of any of the task's parameters. The ESE API will dynamically set and get the values of task parameters. These values will be used in the Run() method unless they are overridden by a corresponding keyword in the Run() method. The parameter name must be fully specified, without abbreviation.

# ESETask::GetParameter

Returns an ESETaskParameter object for the named parameter. If the parameter does not exist, then it returns !null.

## Example

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Parameter = Task.GetParameter( 'a' )

## Syntax

Result = Obj.[ESETask::]GetParameter( Name )

## Return Value

Returns an ESETaskParameter object for the named parameter. If the parameter does not exist, then it returns !null.

## Arguments

### Name

Specifies the name to match.

## Keywords

None.

# ESETask::GetParameters

Returns a list of ESETaskParameter objects.

## Example

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Parameters = Task.GetParameters()

## Syntax

Result = Obj.[ESETask::]GetParameters( [ /NAMES ])

## Return Value

Returns a list of ESETaskParameter objects. If the task does not have any parameters then returns an empty list. If NAMES is set, it returns an array of parameter names, or returns !null if the task does not have any parameters.

## Arguments

None.

## Keywords

### NAMES

Set this keyword to have the method return just the names of the parameters, instead of ESETaskParameter objects.

# ESETask::GetParent

This function returns the ESEService object in which this task resides.

## Example

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Service = Task.GetParent()

## Syntax

Result = Obj.[ESETask::]GetParent()

## Return Value

The return value is the ESEService object that this the parent to the task.

## Arguments

None.

## Keywords

None.

# ESETask::Info

Returns a dictionary with all the properties of the task.

## Example

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Info = Task.Info()

Desc = info.description

## Syntax

Result = Obj.[ESETask::]Info()

## Return Value

The return value is a dictionary with the following fields:

- name: (string) The task's name, which is the name of the PRO-code entry point routine.
- displayName: (string) The task's display name.
- description: (string) The description of the task.
- executionType: (string) The execution type as defined by the constants ESE.synchronous and ESE.asynchronous.
- version: (string) The version of ESE for which the task was designed.
- reset: (string) The task's reset option: { 'no', 'closeEnvi', 'yes', 'full', 'restart' }.
- invocationType: (string) The way in which the task's entry routine will be invoked: { 'keywords', 'positional' }.
- uri: (string) The URI to the task.

## Arguments

None.

## Keywords

None.

# ESETask::Run

Runs the task and produces an ESEJob object, which can be used to monitor status and get the values of output parameters.

The job is run synchronously unless the task is asynchronous and the ASYNCHRONOUS or ASYNC keywords are set. Synchronous tasks are always run synchronously, regardless of the use of the ASYNCHRONOUS and ASYNC keywords.

Input parameter values are specified via keywords. Output parameter names and invalid parameter names throw an error (or cause run to return an ESEJob with error information). The conversion from IDL to JSON is performed by default, or by custom serialization and deserialization methods.

## Example

In this example, the 'ese_addition' task is run. The input parameter 'a' is set on the task object and input parameter 'b' is set when the task is run. The optional input parameter 'c' is not specified.

Task = ESE.FindTask( 'localhost', 'ese_addition' )

Task.a = 1

Job = Task.Run( b = 2 )

PRINT, Job.answer

The value for the output parameter 'answer' can only be retrieved from the ESEJob object.

## Syntax

Job = Obj.[ESETask::]Run( Keywords [, /ASYNC | /ASYNCHRONOUS ] )

## Return Value

This method returns an ESEJob object, which represents the execution of the task. The job contains all the input and output parameter values as well as the execution state (ESE.jobExecuting, ESE.jobSucceeded, ESE.jobFailed, etc.).

## Arguments

None.

## Keywords

### ASYNC

The only allowable abbreviation of the ASYNCHRONOUS keyword.

### ASYNCHRONOUS

Set this keyword to run jobs asynchronously. Only asynchronous jobs can be run asynchronously. This keyword is ignored with synchronous tasks.

### INPUTPARAMETER

Set input parameters to values using normal IDL keyword-value pairs. For example, if a task has a parameter 'mode' then to run it with a value of 2. it as: Task.run( mode = 2 ).

## Version History

IDL 8.4.1 | Introduced

## See Also

ESE, ESEJob, ESEService, ESETaskParameter