---
title: "Scheduler.Job.Run"
slug: "schedulerjobrun"
updated: 2024-08-21T13:28:21Z
published: 2024-08-21T13:28:21Z
canonical: "support.lusid.com/schedulerjobrun"
---

> ## Documentation Index
> Fetch the complete documentation index at: https://support.lusid.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Scheduler.Job.Run

| **Type** | **Read/write** | **Author** | **Availability** |
| --- | --- | --- | --- |
| [Data provider](/v1/docs/what-are-a-data-provider-and-a-direct-provider) | Read | Finbourne | Provided with LUSID |

The `Scheduler.Job.Run` provider enables you to write a [Luminesce SQL query](/v1/docs/understanding-the-luminesce-sql-query-syntax) that kicks off a job run in [Scheduler](/v1/docs/scheduler).

> **Note:** The LUSID user running the query must have sufficient [access control permissions](/v1/docs/creating-policies-to-control-access-to-providers-for-different-luminesce-end-users) 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](/v1/docs/schedulerjob), [Scheduler.Schedule.Run](/v1/docs/schedulerschedulerun)

## Basic usage

```sql
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](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
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](/v1/docs/what-tools-are-available-to-write-luminesce-queries):

```sql
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](https://github.com/finbourne/luminesce-examples/tree/master/examples).

### Example 1: Pass in arguments and run a job

```sql
@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

```sql
@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](/v1/docs/schedulerjobhistorywithlogs) provider is then queried using the run ID to return job history and any console output logs.

```sql
@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;
```
