Class JobStore
Manages job persistence and logging in SQL Server.
Implements
Inherited Members
Namespace: DataWeb.Worker.SqlServer
Assembly: DataWeb.Data.SqlServer.dll
Syntax
public class JobStore : IJobStore
Constructors
JobStore(ISqlHelper, IEnvironmentService, TimeProvider)
Declaration
public JobStore(ISqlHelper sqlHelper, IEnvironmentService environmentService, TimeProvider timeProvider)
Parameters
| Type | Name | Description |
|---|---|---|
| ISqlHelper | sqlHelper | |
| IEnvironmentService | environmentService | |
| TimeProvider | timeProvider |
Properties
Name
Gets the name of the job store
Declaration
public string Name { get; }
Property Value
| Type | Description |
|---|---|
| string |
Methods
ExistsInStatusAsync(string, JobStatus, CancellationToken)
Checks if a job with the specified name exists in the given status.
Declaration
public Task<bool> ExistsInStatusAsync(string name, JobStatus status, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the job to search for. |
| JobStatus | status | The job status to match. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<bool> | True if a job with the specified name and status exists; otherwise false. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when name is null or empty. |
GetJobAsync(JobFilter, CancellationToken)
Retrieves a single job matching the specified filter criteria.
Declaration
public Task<Job> GetJobAsync(JobFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| JobFilter | filter | The filter criteria for the job. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<Job> | The first job matching the filter, or null if no match found. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
GetJobsAsync(JobFilter, CancellationToken)
Retrieves jobs matching the specified filter criteria.
Declaration
public Task<IEnumerable<Job>> GetJobsAsync(JobFilter filter, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| JobFilter | filter | The filter criteria for jobs. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<IEnumerable<Job>> | A collection of jobs matching the filter. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentNullException | Thrown when filter is null. |
GetLogAsync(string, CancellationToken)
Retrieves the complete log file for a job.
Declaration
public Task<string> GetLogAsync(string id, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | id | The ID of the job. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<string> | The contents of the job's log file. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when id is null or empty. |
SetJobAsync(string, int, JobStatus, List<Parameter>, CancellationToken)
Creates a new job with the specified parameters.
Declaration
public Task<string> SetJobAsync(string name, int total, JobStatus status, List<Parameter> parameters = null, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name | The name of the job. |
| int | total | The total number of items to process. |
| JobStatus | status | The initial job status. |
| List<Parameter> | parameters | Optional job parameters. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task<string> | The ID of the newly created job. |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when name is null or empty. |
SetStatusAsync(string, JobStatus, CancellationToken)
Updates the status of a job and sets the end date if completed or cancelled.
Declaration
public Task SetStatusAsync(string jobId, JobStatus status, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | jobId | The ID of the job to update. |
| JobStatus | status | The new job status. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when jobId is null or empty. |
UpdateEntryAsync(string, int, int, CancellationToken)
Updates the progress and error count for a job.
Declaration
public Task UpdateEntryAsync(string jobId, int progress, int errors, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | jobId | The ID of the job to update. |
| int | progress | The current progress value. |
| int | errors | The current error count. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when jobId is null or empty. |
UpdateTextLogAsync(string, string, CancellationToken)
Appends a line to the job's log file.
Declaration
public Task UpdateTextLogAsync(string jobId, string line, CancellationToken cancellationToken = default)
Parameters
| Type | Name | Description |
|---|---|---|
| string | jobId | The ID of the job. |
| string | line | The line to append to the log. |
| CancellationToken | cancellationToken | Cancellation token. |
Returns
| Type | Description |
|---|---|
| Task |
Exceptions
| Type | Condition |
|---|---|
| ArgumentException | Thrown when jobId is null or empty. |