Jobs client

The Scripting SDK provides a Jobs client to perform CRUD operations on entities.

Note

To help you update code from the Entities client to the Jobs client, we provide several examples.

GetTargetsAsync

This method retrieves the targets for a job and supports the JobTargetQuery request parameter. This parameter is the job target query request and represents a request for job targets with various filtering options. It allows you to specify criteria to narrow down the job targets you are interested in.

The properties supported by this method are listed in the following table.

Property

Type

Description

JobId

long

The unique ID of the job.

State

string

The state of the job target (optional). This can be used to filter targets based on their current state.

Condition

string

The condition of the job target (optional). This can be used to filter targets based on specific conditions.

Type

string

The type of the job target (optional). This can be used to filter targets based on their type.

Location

string

The location of the job target (optional). This can be used to filter targets based on their geographical location.

Skip

int

The number of records to skip. This is useful for pagination.

Take

int

The number of records to take. This is useful for pagination. The default value is 25.

Cultures

CultureInfo[]

The cultures information to load the entity (optional). If no cultures are provided, multi-language properties won't be included. The default value is an array containing CultureInfo.InvariantCulture.

In the following example, the JobTargetQuery is used to request job targets for a specific job (JobId = 123) with various filters applied, such as state, condition, type, and location. The query will skip 0 records and take 50 records, and it will include multi-language properties for English (US) and French (FR) cultures.

RequestResponse
var jobTargetQuery = new JobTargetQuery(123)
{
    State = "Waiting",
    Condition = "Pending",
    Type = "System",
    Location = "67890",
    Skip = 0,
    Take = 50,
    Cultures = new[] { new CultureInfo("en-US"), new CultureInfo("fr-FR") }
};

This example calls the client method.

RequestResponse
using Stylelabs.M.Sdk.Contracts.Jobs;

var jobTargetQuery = new JobTargetQuery(123)
{
    State = "Waiting",
    Skip = 0,
    Take = 10
};

IEntityCollectionResult targets = await MClient.Jobs.GetTargetsAsync(jobTargetQuery);

The method returns the collection of job targets Task<IEntityCollectionResult>. . The following exceptions can occur:

  • ArgumentNullException - if the request is null.

  • ArgumentOutOfRangeException - if the request.Take or the request.Skip values are negative numbers, or the request.JobId is not a valid ID.

  • ArgumentException - if any request.cultures are null or the job entity is not found.

GetTargetAsync

This method retrieves a specific target for a job.

The properties supported by this method are listed in the following table.

Property

Type

Description

JobId

long

The unique ID of the job.

TargetId

long

The target ID.

Cultures

CultureInfo[]

The cultures information to load the entity (optional). If no cultures are provided, multi-language properties won't be included. The default value is an array containing CultureInfo.InvariantCulture.

In the following example,

RequestResponse
IEntity description = await MClient.Jobs.GetTargetAsync(jobId, targetId);

The method returns the specific target entity Task<IEntity>. The following exceptions can occur:

  • ArgumentException - if the JobId or TargetId are not valid.

  • WebApiException - if the HTTP request fails.

SaveTargetAsync

This method creates or updates a target for a job. It supports the following parameters.

Parameter

Type

Description

jobId

long

The job ID.

target

IEntity

The target entity.

The method returns the ID of the saved target Task<long>. The following exceptions can occur:

  • ArgumentNullException - if the target is null.

  • ArgumentException - if the job entity is not found.

  • ArgumentOutOfRangeException - if the job ID is not a valid ID.

Use the following syntax with this method.

RequestResponse
long targetId = await MClient.Jobs.SaveTargetAsync(123, targetEntity);

DeleteTargetAsync

This method deletes a target for a job. It supports the following parameters:

Parameter

Type

Description

jobId

long

The job ID.

targetId

long

The target ID.

The method returns a task that represents the asynchronous operation. The following exceptions can occur:

  • ArgumentException - if the job ID or target ID are invalid.

  • ArgumentOutOfRangeException - if the job ID or target ID are not a valid IDs.

Use the following syntax with this method.

RequestResponse
await MClient.Jobs.DeleteTargetAsync(123, 456);

GetDescriptionAsync

This method retrieves the description of a job. It supports the following parameters:

Parameter

Type

Description

jobId

long

The job ID.

cultures

CultureInfo[]

Optional cultures for the description.

The method returns the job description entity Task<IEntity>. The following exceptions can occur:

  • ArgumentException - if the job ID is invalid.

  • ArgumentOutOfRangeException - if the job ID is not a valid ID.

Use the following syntax with this method.

RequestResponse
IEntity jobDescription = await MClient.Jobs.GetDescriptionAsync(123);

SaveDescriptionAsync

This method creates or updates the description of a job. It supports the following parameters:

Parameter

Type

Description

jobId

long

The job ID.

jobDescription

IEntity

The job description entity.

The method returns the ID of the saved job description Task<long>. The following exceptions can occur:

  • ArgumentNullException - if the job description is null.

  • ArgumentException - if the job ID or job description ID is invalid.

  • ArgumentOutOfRangeException - if the if the job ID is not a valid ID.

Use the following syntax with this method.

RequestResponse
long descriptionId = await MClient.Jobs.SaveDescriptionAsync(123, jobDescriptionEntity);

DeleteDescriptionAsync

This method deletes the description of a job. It supports the following parameter.

Parameter

Type

Description

jobId

long

The job ID.

The method returns a task representing the asynchronous operation. The following exceptions can occur:

  • ArgumentException - if the job or description entities are not found.

  • ArgumentOutOfRangeException - if the job ID is not a valid ID.

Use the following syntax with this method.

RequestResponse
await MClient.Jobs.DeleteDescriptionAsync(123);

Do you have some feedback for us?

If you have suggestions for improving this article,