Views:
TypeRead/writeAuthorAvailability
Data providerReadFinbourneProvided with LUSID

The Scheduler.Job.Run provider enables you to write a Luminesce SQL query that kicks off a job run in Scheduler.

Note: The LUSID user running the query must have sufficient access control permissions to both use the provider and run jobs in Scheduler. This should automatically be the case if you are the domain owner.

See also: Scheduler.Job, Scheduler.Schedule.Run

Basic usage

select * from Scheduler.Job.Run
where Scope = <scope> 
and Code = <code>;

Query parameters

Scheduler.Job.Run has parameters that enable you to filter or refine a query.

Note: The Scope and Code parameters are mandatory.

To list available parameters, their data types, default values, and an explanation for each, run the following query using a suitable tool:

select FieldName, DataType, ParamDefaultValue, Description from Sys.Field where TableName = 'Scheduler.Job.Run' and FieldType = 'Parameter';

Data fields

By default, Scheduler.Job.Run returns a table of data populated with particular fields (columns). You can return a subset of these fields.

To list fields available to return, their data types, whether fields are considered 'main', and an explanation for each, run the following query using a suitable tool:

select FieldName, DataType, IsMain, IsPrimaryKey, SampleValues, Description from Sys.Field where TableName = 'Scheduler.Job.Run' and FieldType = 'Column';

Note: Fields marked 'main' are returned by queries that start select ^ from Scheduler.Job.Run.

Examples

Note: For more example Luminesce SQL queries, visit our Github repo.

Example 1: Pass in arguments and run a job

@args =
select
  json_object(
      '--scope', 'Finbourne-Examples',
      '--code', 'UK-Equities'
    ) arguments;

select * from Scheduler.Job.Run
where Scope = 'transactions'
  and Code = 'upsert-transactions'
  and StartJobArguments = @args;

Example 2: Pass in notifications as arguments and run a job

@args =
select
  json_object(
      '--scope', 'Finbourne-Examples',
      '--code', 'UK-Equities'
    ) arguments,
  json_array(
    json_object(
      'FireOn', 'Succeeded',
      'Transport', 'Email',
      'Destination', json_array('joebloggs@acme.com')
  )) notifications;

select * from Scheduler.Job.Run
where Scope = 'transactions'
  and Code = 'upsert-transactions'
  and StartJobArguments = @args;

Example 3: Run a job and retrieve job history and logs

In this example, the WaitForCompletion parameter is passed into the query to make it wait for the specified number of seconds before returning a result. A table of data is returned as soon as the job completes, or if the job does not complete within the specified time, the current status of the job is returned. The Scheduler.Job.HistoryWithLogs provider is then queried using the run ID to return job history and any console output logs. 

@args =
select
  json_object(
      '--scope', 'Finbourne-Examples',
      '--code', 'UK-Equities'
    ) arguments;

@@runId =
select RunId from Scheduler.Job.Run
where Scope = 'transactions'
  and Code = 'upsert-transactions'
  and StartJobArguments = @args
  and WaitForCompletion = 60;

select * from Scheduler.Job.HistoryWithLogs where RunId = @@runId;