November Happy Hour will be moved to Thursday December 5th.

Class ScheduledJob

Read, edit and execute scheduled jobs

Inheritance
System.Object
ScheduledJob
Namespace: EPiServer.DataAbstraction
Assembly: EPiServer.dll
Version: 12.0.3
Syntax
public class ScheduledJob : Object
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

ScheduledJob()

Initializes a new instance of the ScheduledJob class.

Declaration
public ScheduledJob()

ScheduledJob(Guid, String, Boolean, DateTime, DateTime, Boolean, String, ScheduledIntervalType, Int32, String, Boolean, String, String, Byte[])

Initializes a new instance of the ScheduledJob class.

Declaration
public ScheduledJob(Guid id, string name, bool enabled, DateTime lastExec, DateTime nextExec, bool lastFailed, string lastText, ScheduledIntervalType datePart, int interval, string methodName, bool isStatic, string typeName, string assemblyName, byte[] data)
Parameters
Type Name Description
System.Guid id

The id of the ScheduledJob.

System.String name

The name of the ScheduledJob.

System.Boolean enabled

if set to true the scheduled job is enabled.

System.DateTime lastExec

A System.DateTime for last execution, System.DateTime.MinValue is identical with no last execution date.

System.DateTime nextExec

A System.DateTime for next execution, System.DateTime.MinValue is identical with no next execution date.

System.Boolean lastFailed

if set to true the last execution failed.

System.String lastText

Informational message on last execution if any.

ScheduledIntervalType datePart

The interval unit.

System.Int32 interval

The interval.

System.String methodName

Name of the method.

System.Boolean isStatic

if set to true the method to be executed (specified by methodName) is static.

System.String typeName

Name of the type.

System.String assemblyName

Name of the assembly.

System.Byte[] data

The data.

ScheduledJob(Guid, String, Boolean, DateTime, DateTime, DateTime, Boolean, String, ScheduledIntervalType, Int32, String, Boolean, String, String, Byte[])

Initializes a new instance of the ScheduledJob class.

Declaration
public ScheduledJob(Guid id, string name, bool enabled, DateTime lastExec, DateTime nextExec, DateTime nextExecUTC, bool lastFailed, string lastText, ScheduledIntervalType datePart, int interval, string methodName, bool isStatic, string typeName, string assemblyName, byte[] data)
Parameters
Type Name Description
System.Guid id

The id of the ScheduledJob.

System.String name

The name of the ScheduledJob.

System.Boolean enabled

if set to true the scheduled job is enabled.

System.DateTime lastExec

A System.DateTime for last execution, System.DateTime.MinValue is identical with no last execution date.

System.DateTime nextExec

A System.DateTime for next execution, System.DateTime.MinValue is identical with no next execution date.

System.DateTime nextExecUTC

A System.DateTime (UTC) of the next scheduled execution.

System.Boolean lastFailed

if set to true the last execution failed.

System.String lastText

Informational message on last execution if any.

ScheduledIntervalType datePart

The interval unit.

System.Int32 interval

The interval.

System.String methodName

Name of the method.

System.Boolean isStatic

if set to true the method to be executed (specified by methodName) is static.

System.String typeName

Name of the type.

System.String assemblyName

Name of the assembly.

System.Byte[] data

The data.

ScheduledJob(String, ScheduledMethod)

Initializes a new instance of the ScheduledJob class.

Declaration
public ScheduledJob(string jobName, ScheduledMethod method)
Parameters
Type Name Description
System.String jobName

The name of the ScheduledJob.

ScheduledMethod method

The method to execute when the scheduled job runs.

Properties

AssemblyName

Gets or sets the name of the assembly that holds the type.

Declaration
public string AssemblyName { get; set; }
Property Value
Type Description
System.String

CurrentStatusMessage

Gets or sets the current status message for the job

Declaration
public string CurrentStatusMessage { get; set; }
Property Value
Type Description
System.String

HasLastExecutionFailed

Gets or sets and indiciation if the last execution failed

Declaration
public bool HasLastExecutionFailed { get; set; }
Property Value
Type Description
System.Boolean

ID

Gets or sets the unique identifier of the job.

Declaration
public Guid ID { get; set; }
Property Value
Type Description
System.Guid

InstanceData

Get the raw serialized class if method isnt static

Declaration
public byte[] InstanceData { get; }
Property Value
Type Description
System.Byte[]

IntervalLength

Gets or sets the length of intervals between execution

Declaration
public int IntervalLength { get; set; }
Property Value
Type Description
System.Int32

IntervalType

Gets or sets the interval type

Declaration
public ScheduledIntervalType IntervalType { get; set; }
Property Value
Type Description
ScheduledIntervalType

IsEnabled

Gets or sets and indication if job is enabled for scheduling

Declaration
public bool IsEnabled { get; set; }
Property Value
Type Description
System.Boolean

IsRunning

Gets or sets the running state of the job

Declaration
public bool IsRunning { get; set; }
Property Value
Type Description
System.Boolean

IsServiceOnline

If the scheduler service is online

Declaration
public static bool IsServiceOnline { get; }
Property Value
Type Description
System.Boolean

IsStaticMethod

Gets or sets if the method is static (and does not contain instance data)

Declaration
public bool IsStaticMethod { get; set; }
Property Value
Type Description
System.Boolean

IsStoppable

Gets if the job is stoppable

Declaration
public bool IsStoppable { get; set; }
Property Value
Type Description
System.Boolean

LastExecution

Gets or sets the date of the last execution.

Declaration
public DateTime LastExecution { get; set; }
Property Value
Type Description
System.DateTime
Remarks

A value of System.DateTime.MinValue indicates that the job has not been executed.

LastExecutionAttempt

Last execution attempt

Declaration
public int LastExecutionAttempt { get; }
Property Value
Type Description
System.Int32

LastExecutionMessage

Gets or sets an informational message on last exection if any

Declaration
public string LastExecutionMessage { get; set; }
Property Value
Type Description
System.String

LastExecutionStatus

Gets or sets the last execution status

Declaration
public ScheduledJobExecutionStatus LastExecutionStatus { get; }
Property Value
Type Description
ScheduledJobExecutionStatus

MethodName

Gets or sets the name of the method to be called on execution.

Declaration
public string MethodName { get; set; }
Property Value
Type Description
System.String
Remarks

For a method with the following signature

public static string Execute()

the name should simply be Execute

Name

Gets or sets a name of the job

Declaration
public string Name { get; set; }
Property Value
Type Description
System.String

NextExecution

Gets or sets the date of the next execution.

Declaration
public DateTime NextExecution { get; set; }
Property Value
Type Description
System.DateTime
Remarks

A value of System.DateTime.MinValue is regarded as no next execution date is set.

NextExecutionUTC

Gets the original read-only UTC date for next execution

Declaration
public DateTime NextExecutionUTC { get; set; }
Property Value
Type Description
System.DateTime

PingTime

Gets or sets the ping time of the job.

Declaration
public TimeSpan PingTime { get; set; }
Property Value
Type Description
System.TimeSpan

Restartable

Indicates if the Job is restartable

Declaration
public bool Restartable { get; }
Property Value
Type Description
System.Boolean

SecondsAfterLastPing

Gets the ping time.

Declaration
public int SecondsAfterLastPing { get; set; }
Property Value
Type Description
System.Int32

TypeName

Gets or sets the full name of the type that holds the method to execute.

Declaration
public string TypeName { get; set; }
Property Value
Type Description
System.String
Remarks

For the following class definition

namespace Example
{
	public class MyJob
	...

the TypeName should be "Example.MyJob"

Methods

Equals(Object)

Determines whether the specified System.Object is equal to this instance.

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj

The System.Object to compare with this instance.

Returns
Type Description
System.Boolean

true if the specified System.Object is equal to this instance; otherwise, false.

Exceptions
Type Condition
System.NullReferenceException

The obj parameter is null.

GetHashCode()

Returns a hash code for this instance.

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32

A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.

SetServicePingDate()

Do not call this method from code, it is called by the service

Declaration
public static void SetServicePingDate()

Operators

Equality(ScheduledJob, ScheduledJob)

Implements the operator ==.

Declaration
public static bool operator ==(ScheduledJob x, ScheduledJob y)
Parameters
Type Name Description
ScheduledJob x

The x.

ScheduledJob y

The y.

Returns
Type Description
System.Boolean

The result of the operator.

Inequality(ScheduledJob, ScheduledJob)

Implements the operator !=.

Declaration
public static bool operator !=(ScheduledJob x, ScheduledJob y)
Parameters
Type Name Description
ScheduledJob x

The x.

ScheduledJob y

The y.

Returns
Type Description
System.Boolean

The result of the operator.

Extension Methods