Table of Contents

Class OpenBiApiClientBatchJobExtensions

Namespace
BiExcellence.OpenBi.Api.BatchJobs
Assembly
BiExcellence.OpenBi.Api.Client.dll

Extension methods for the /batchjobs, /batchjobhandlers and /batchjoblogs REST APIs.

public static class OpenBiApiClientBatchJobExtensions
Inheritance
object
OpenBiApiClientBatchJobExtensions

Methods

AssignBatchJobUsergroupAsync(IOpenBiApiClient, int, string, CancellationToken)

Gives a usergroup access to a batch job (POST batchjobs/{id}/usergroups/{usergroupId}): its members see the job and may run it. Idempotent; RemoveBatchJobUsergroupAsync(IOpenBiApiClient, int, string, CancellationToken) undoes it. Throws OpenBiApiException (404) when there is no usergroup with that id.

public static Task AssignBatchJobUsergroupAsync(this IOpenBiApiClient client, int id, string usergroupId, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
usergroupId string
cancellationToken CancellationToken

Returns

Task

CancelBatchJobLogAsync(IOpenBiApiClient, long, CancellationToken)

Requests cancellation of a currently-running batch job run (POST batchjoblogs/{id}/cancel). Throws OpenBiApiException with 404 when no run with this id is going on this server - which is also the answer for one that has already finished - and with 403 when the run executes as another user and the caller is no batch job administrator.

public static Task CancelBatchJobLogAsync(this IOpenBiApiClient client, long id, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id long
cancellationToken CancellationToken

Returns

Task

CreateBatchJobAsync(IOpenBiApiClient, BatchJob, CancellationToken)

Creates a batch job (POST batchjobs) and returns it with its server-assigned id. Handler has to be the code of one of GetBatchJobHandlersAsync(IOpenBiApiClient, CancellationToken); UserId defaults to the caller, and only a batch job administrator may create a job for someone else (403 otherwise). Usergroups are assigned separately with AssignBatchJobUsergroupAsync(IOpenBiApiClient, int, string, CancellationToken).

public static Task<BatchJob?> CreateBatchJobAsync(this IOpenBiApiClient client, BatchJob batchJob, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
batchJob BatchJob
cancellationToken CancellationToken

Returns

Task<BatchJob>

DeleteBatchJobAsync(IOpenBiApiClient, int, CancellationToken)

Deletes a batch job (DELETE batchjobs/{id}) together with its parameters, its usergroup assignments and its run history - its BatchJobLog and BatchJobLogEntry rows go too. A caller without the batch job administrator permission can only delete their own jobs; deleting a job that is not there, or not theirs, is not an error.

public static Task DeleteBatchJobAsync(this IOpenBiApiClient client, int id, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
cancellationToken CancellationToken

Returns

Task

ExecuteBatchJobAsync(IOpenBiApiClient, int, Dictionary<string, string>?, CancellationToken)

Runs a batch job immediately and streams its log entries as they are produced. The REST equivalent of the legacy /OPENBI/JOBS/batchjob.biex endpoint. Enumeration ends when the run does; abandoning it (or cancelling cancellationToken) closes the connection but does not stop the job - use CancelBatchJobLogAsync(IOpenBiApiClient, long, CancellationToken) for that. parameters are laid over the job's stored parameters for this run only. The job runs whether or not it is active; the call fails with OpenBiApiException (404) when there is no such job or the caller may not see it. A failure during the run is reported as a log entry, not as an exception.

public static IAsyncEnumerable<BatchJobLogEntry> ExecuteBatchJobAsync(this IOpenBiApiClient client, int id, Dictionary<string, string>? parameters = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
parameters Dictionary<string, string>
cancellationToken CancellationToken

Returns

IAsyncEnumerable<BatchJobLogEntry>

ExecuteBatchJobEventAsync(IOpenBiApiClient, string, string, Dictionary<string, string>?, CancellationToken)

Runs every active batch job registered for the given event and streams their log entries as they are produced. The REST equivalent of the legacy /OPENBI/EVENTHANDLER/batchjob.biex endpoint. The jobs run are the active EVENT and SYSTEM jobs whose EventName and EventValue both match; both arguments are required (400 otherwise).

public static IAsyncEnumerable<BatchJobLogEntry> ExecuteBatchJobEventAsync(this IOpenBiApiClient client, string eventName, string eventValue, Dictionary<string, string>? parameters = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
eventName string
eventValue string
parameters Dictionary<string, string>
cancellationToken CancellationToken

Returns

IAsyncEnumerable<BatchJobLogEntry>

GetBatchJobAsync(IOpenBiApiClient, int, CancellationToken)

Reads one batch job, including its parameters and usergroup ids (GET batchjobs/{id}). Throws OpenBiApiException (404) when there is no such job, or when the caller may not see it.

public static Task<BatchJob> GetBatchJobAsync(this IOpenBiApiClient client, int id, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
cancellationToken CancellationToken

Returns

Task<BatchJob>

GetBatchJobHandlersAsync(IOpenBiApiClient, CancellationToken)

Lists the batch job handler types registered on the server (GET batchjobhandlers): the values Handler accepts, each with the parameters it expects. Plugins contribute handlers, so the list depends on what is installed.

public static Task<OpenBiListResult<BatchJobHandler>> GetBatchJobHandlersAsync(this IOpenBiApiClient client, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
cancellationToken CancellationToken

Returns

Task<OpenBiListResult<BatchJobHandler>>

GetBatchJobLogEntriesAsync(IOpenBiApiClient, long, OpenBiListRequest?, CancellationToken)

Lists the log entries written during one batch job run, oldest first (GET batchjoblogs/{id}/entries). A run that is still going can be followed without re-reading what has already been shown by filtering on an id greater than the last one seen. A caller without the batch job administrator permission only sees the entries of jobs they own.

public static Task<OpenBiListResult<BatchJobLogEntry>> GetBatchJobLogEntriesAsync(this IOpenBiApiClient client, long id, OpenBiListRequest? request = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id long
request OpenBiListRequest
cancellationToken CancellationToken

Returns

Task<OpenBiListResult<BatchJobLogEntry>>

GetBatchJobLogsAsync(IOpenBiApiClient, int?, OpenBiListRequest?, CancellationToken)

Lists batch job runs, newest first, optionally restricted to a single job (GET batchjoblogs). A caller without the batch job administrator permission only sees runs of jobs they own. The lines of a run are read with GetBatchJobLogEntriesAsync(IOpenBiApiClient, long, OpenBiListRequest?, CancellationToken).

public static Task<OpenBiListResult<BatchJobLog>> GetBatchJobLogsAsync(this IOpenBiApiClient client, int? jobId = null, OpenBiListRequest? request = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
jobId int?
request OpenBiListRequest
cancellationToken CancellationToken

Returns

Task<OpenBiListResult<BatchJobLog>>

GetBatchJobUsergroupsAsync(IOpenBiApiClient, int, OpenBiListRequest?, CancellationToken)

Lists the usergroups a batch job is assigned to (GET batchjobs/{id}/usergroups) - members of these groups see the job and may run it even without the batch job administrator permission.

public static Task<OpenBiListResult<Usergroup>> GetBatchJobUsergroupsAsync(this IOpenBiApiClient client, int id, OpenBiListRequest? request = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
request OpenBiListRequest
cancellationToken CancellationToken

Returns

Task<OpenBiListResult<Usergroup>>

GetBatchJobsAsync(IOpenBiApiClient, long?, OpenBiListRequest?, CancellationToken)

Lists batch jobs (GET batchjobs). Without parentLogId only top-level jobs are listed - those whose ParentLogId is null; with it, the jobs created from that run. A caller without the batch job administrator permission only sees jobs they own or that are assigned to one of their usergroups. The list leaves Parameters and UsergroupIds empty - read one job with GetBatchJobAsync(IOpenBiApiClient, int, CancellationToken) for those.

public static Task<OpenBiListResult<BatchJob>> GetBatchJobsAsync(this IOpenBiApiClient client, long? parentLogId = null, OpenBiListRequest? request = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
parentLogId long?
request OpenBiListRequest
cancellationToken CancellationToken

Returns

Task<OpenBiListResult<BatchJob>>

RemoveBatchJobUsergroupAsync(IOpenBiApiClient, int, string, CancellationToken)

Takes a usergroup off a batch job (DELETE batchjobs/{id}/usergroups/{usergroupId}). Removes the link only; the usergroup and the job stay.

public static Task RemoveBatchJobUsergroupAsync(this IOpenBiApiClient client, int id, string usergroupId, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
usergroupId string
cancellationToken CancellationToken

Returns

Task

RunBatchJobAsync(IOpenBiApiClient, int, Dictionary<string, string>?, CancellationToken)

Runs a batch job immediately and returns its log entries once the run has finished. Same endpoint as ExecuteBatchJobAsync(IOpenBiApiClient, int, Dictionary<string, string>?, CancellationToken), without the streaming - prefer this when the log is only of interest after the fact.

public static Task<IReadOnlyList<BatchJobLogEntry>> RunBatchJobAsync(this IOpenBiApiClient client, int id, Dictionary<string, string>? parameters = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
parameters Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<BatchJobLogEntry>>

RunBatchJobEventAsync(IOpenBiApiClient, string, string, Dictionary<string, string>?, CancellationToken)

Runs every active batch job registered for the given event and returns their log entries once all runs have finished.

public static Task<IReadOnlyList<BatchJobLogEntry>> RunBatchJobEventAsync(this IOpenBiApiClient client, string eventName, string eventValue, Dictionary<string, string>? parameters = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
eventName string
eventValue string
parameters Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<IReadOnlyList<BatchJobLogEntry>>

StartBatchJobAsync(IOpenBiApiClient, int, Dictionary<string, string>?, CancellationToken)

Starts a batch job and returns as soon as it is under way, without waiting for it or reading its log. Same endpoint as the two above with ?detached: the run is cut loose from the request, so unlike them it keeps going after this returns and is unaffected by cancellationToken once started - only CancelBatchJobLogAsync(IOpenBiApiClient, long, CancellationToken) stops it. Read its log afterwards with GetBatchJobLogEntriesAsync(IOpenBiApiClient, long, OpenBiListRequest?, CancellationToken) on the returned JobLogId.

public static Task<StartedBatchJob> StartBatchJobAsync(this IOpenBiApiClient client, int id, Dictionary<string, string>? parameters = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
parameters Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task<StartedBatchJob>

StartBatchJobEventAsync(IOpenBiApiClient, string, string, Dictionary<string, string>?, CancellationToken)

Starts every active batch job registered for the given event and returns as soon as they are under way. The ?detached counterpart of the two above; nothing is returned because an event triggers any number of jobs, so there is no one log to point at - find the runs with GetBatchJobLogsAsync(IOpenBiApiClient, int?, OpenBiListRequest?, CancellationToken).

public static Task StartBatchJobEventAsync(this IOpenBiApiClient client, string eventName, string eventValue, Dictionary<string, string>? parameters = null, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
eventName string
eventValue string
parameters Dictionary<string, string>
cancellationToken CancellationToken

Returns

Task

UpdateBatchJobAsync(IOpenBiApiClient, int, BatchJob, CancellationToken)

Creates or updates the batch job with the given id (POST batchjobs/{id}) - an id that is not there yet is inserted. The stored parameters are replaced by Parameters; UsergroupIds, ParentLogId and LastRunDate are ignored. Only a batch job administrator may save a job whose UserId is not the caller (403 otherwise).

public static Task<BatchJob?> UpdateBatchJobAsync(this IOpenBiApiClient client, int id, BatchJob batchJob, CancellationToken cancellationToken = default)

Parameters

client IOpenBiApiClient
id int
batchJob BatchJob
cancellationToken CancellationToken

Returns

Task<BatchJob>