Class ScheduledJobRepository
Get, list, save and delete scheduled jobs
Inheritance
Inherited Members
Namespace: EPiServer.DataAbstraction
Assembly: EPiServer.dll
Version: 9.12.2Syntax
[ServiceConfiguration]
[ServiceConfiguration(typeof(IScheduledJobRepository))]
[ServiceConfiguration(typeof(IScheduledJobStatusService))]
public class ScheduledJobRepository : IScheduledJobRepository, IScheduledJobStatusService
Remarks
The best way to create a custom scheduled job is to use the ScheduledPlugInAttribute as it will automatically generate a settings page in admin mode.
All dates exposed by ScheduledJob are in local time, but they will be saved to the database as UTC dates.
Examples
Example that demonstrates listing all available jobs.
var repo = ServiceLocator.Current.GetInstance<IScheduledJobRepository>();
foreach (ScheduledJob job in repo.List())
{
Response.Write("Name=" + job.Name);
}
Constructors
ScheduledJobRepository()
Declaration
public ScheduledJobRepository()
Methods
Delete(Guid)
Deletes a job by id
Declaration
public virtual void Delete(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id |
Get(Guid)
Get a job by id
Declaration
public virtual ScheduledJob Get(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The id of the job |
Returns
Type | Description |
---|---|
ScheduledJob | The job, or null if not found |
Get(String, String, String)
Get a job by method, type name and assembly
Declaration
public virtual ScheduledJob Get(string method, string typeName, string assemblyName)
Parameters
Type | Name | Description |
---|---|---|
System.String | method | The method to call. |
System.String | typeName | Name of the class where method lives. |
System.String | assemblyName | Name of the assembly where the class is defined. |
Returns
Type | Description |
---|---|
ScheduledJob | A ScheduledJob instance if a matching job is found, otherwise null. |
GetExecutionLog(Guid)
List log information for the ScheduledJob.
Declaration
public virtual IEnumerable<ScheduledJobLogItem> GetExecutionLog(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id |
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ScheduledJobLogItem> |
Remarks
Method returns a maximum of 100 log items
GetNextScheduledJob()
Get the next job up for execution
Declaration
public virtual ScheduledJob GetNextScheduledJob()
Returns
Type | Description |
---|---|
ScheduledJob | A ScheduledJob instance if there is a waiting job, otherwise null. |
List()
Retrieves a list of all available jobs
Declaration
public virtual IEnumerable<ScheduledJob> List()
Returns
Type | Description |
---|---|
System.Collections.Generic.IEnumerable<ScheduledJob> |
LoadLog(Guid)
Loads log information for the ScheduledJob.
Declaration
public virtual DataTable LoadLog(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id |
Returns
Type | Description |
---|---|
System.Data.DataTable | A System.Data.DataTable containing log data where each row represents a log event. |
MarkAsFailed(Guid)
Mark the scheduled job as failed to prevent it from being executed. This flag is only temporary and execution will start again when the application has been restarted.
Declaration
public virtual void MarkAsFailed(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The job identifier |
MarkForExecution(Guid, DateTime, TimeSpan)
Declaration
[Obsolete("Renamed to TryMarkForExecution")]
public virtual bool MarkForExecution(Guid id, DateTime validateUtcDate, TimeSpan pingTime)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | |
System.DateTime | validateUtcDate | |
System.TimeSpan | pingTime |
Returns
Type | Description |
---|---|
System.Boolean |
ReportExecutedJob(Guid, Boolean, String)
Report a job as executed
Declaration
public virtual void ReportExecutedJob(Guid id, bool success, string message)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | Job id |
System.Boolean | success | If the job executed successfully |
System.String | message | Message |
Save(ScheduledJob)
Saves job information or creates a new job
Declaration
public virtual void Save(ScheduledJob job)
Parameters
Type | Name | Description |
---|---|---|
ScheduledJob | job |
TryMarkForExecution(Guid, DateTime, TimeSpan)
Marks a job for execution
Declaration
public virtual bool TryMarkForExecution(Guid id, DateTime validateUtcDate, TimeSpan pingTime)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The identity |
System.DateTime | validateUtcDate | The expected execution time that should be validated |
System.TimeSpan | pingTime | The expected ping time |
Returns
Type | Description |
---|---|
System.Boolean | True if the job was successfully marked for execution |
UpdateCurrentStatusMessage(Guid, String)
Updates current status message for a running job
Declaration
public virtual void UpdateCurrentStatusMessage(Guid id, string message)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The job id |
System.String | message | Status message |
UpdateRunningState(Guid, Boolean)
Update running state
Declaration
public virtual void UpdateRunningState(Guid id, bool isRunning)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | Job id |
System.Boolean | isRunning | If job is running or not |
Events
ScheduledJobDeleted
Declaration
public static event EventHandler<EventArgs> ScheduledJobDeleted
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |
ScheduledJobSaved
Declaration
public static event EventHandler<EventArgs> ScheduledJobSaved
Event Type
Type | Description |
---|---|
System.EventHandler<System.EventArgs> |