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

Class ScheduledJob

Read, edit and execute scheduled jobs

Inheritance
System.Object
ScheduledJob
Inherited Members
System.Object.ToString()
System.Object.Equals(System.Object, System.Object)
System.Object.ReferenceEquals(System.Object, System.Object)
System.Object.GetType()
System.Object.MemberwiseClone()
Namespace: EPiServer.DataAbstraction
Assembly: EPiServer.dll
Version: 10.10.4
Syntax
public class ScheduledJob
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(Guid, String, Boolean, DateTime, DateTime, DateTime, Boolean, String, ScheduledIntervalType, Int32, String, Boolean, String, String, Byte[], TimeSpan)

Initializes a new instance of the ScheduledJob class.

Declaration
[Obsolete("Use other constructor. Individual per job ping times has been deprecated in favor of system wide configuration using EPiServer.Scheduler.Internal.SchedulerOptions.")]
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, TimeSpan pingTime)
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 sceduled execution.

System.Boolean lastFailed

if set to true the last execution failed.

System.String lastText

Informational message on last exection 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.

System.TimeSpan pingTime

The ping sleep.

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
[Obsolete("Individual per job ping times has been deprecated in favor of system wide configuration using EPiServer.Scheduler.Internal.SchedulerOptions.")]
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.

Overrides
System.Object.Equals(System.Object)
Exceptions
Type Condition
System.NullReferenceException

The obj parameter is null.

Execute(Boolean)

Execute the current job manually and add interval to NextExecute date

Declaration
[Obsolete("Use IScheduledJobExecutor to execute a job.")]
public void Execute(bool startThread)
Parameters
Type Name Description
System.Boolean startThread

If job should be started in a new thread

Remarks

The job will not execute if another process has already started the job and updated NextExecution.

Execute(Boolean, DateTime)

Execute the current job manually and add interval to NextExecute date

Declaration
[Obsolete("Use IScheduledJobExecutor to execute a job.")]
public void Execute(bool startThread, DateTime validateUtcDate)
Parameters
Type Name Description
System.Boolean startThread

If job should be started in a new thread

System.DateTime validateUtcDate

Validate date with current UTC date

Remarks

The job will not execute if another process has already started the job and updated NextExecution.

ExecuteManually()

Force the job to execute and only update NextExecute date if it is set to a passed date.

Declaration
[Obsolete("Use IScheduledJobExecutor to execute a job.")]
public void ExecuteManually()

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.

Overrides
System.Object.GetHashCode()

IsJobRunning(Guid)

Get the running state for a job

Declaration
[Obsolete("Use IScheduledJobRepository to get job and check if it's running.")]
public static bool IsJobRunning(Guid scheduledJobId)
Parameters
Type Name Description
System.Guid scheduledJobId

Job to check running state for

Returns
Type Description
System.Boolean

True if it running, otherwise false

ListRunningJobs()

Retrieves a list of all running jobs

Declaration
[Obsolete("Use IScheduledJobExecutor to list all running jobs.")]
public static IList<ScheduledJobBase> ListRunningJobs()
Returns
Type Description
System.Collections.Generic.IList<ScheduledJobBase>

SetServicePingDate()

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

Declaration
public static void SetServicePingDate()

Stop()

Tries to stop the job if its running

Declaration
[Obsolete("Use IScheduledJobExecutor to stop a job that is currently running.")]
public void Stop()

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