Class ScheduledJob
Read, edit and execute scheduled jobs
Inheritance
Inherited Members
Namespace: EPiServer.DataAbstraction
Assembly: EPiServer.dll
Version: 9.12.2Syntax
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 |
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 |
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 |
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 |
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 |
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 |
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
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 |
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 |
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 |
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
The name of the assembly that holds the type
Declaration
public string AssemblyName { get; set; }
Property Value
Type | Description |
---|---|
System.String |
CurrentStatusMessage
Gets the current status message for the Job
Declaration
public string CurrentStatusMessage { get; set; }
Property Value
Type | Description |
---|---|
System.String |
HasLastExecutionFailed
If last execution failed
Declaration
public bool HasLastExecutionFailed { get; }
Property Value
Type | Description |
---|---|
System.Boolean |
ID
The job unique identifier
Declaration
public Guid ID { get; set; }
Property Value
Type | Description |
---|---|
System.Guid |
InstanceData
Raw serialized class if method isnt static
Declaration
public byte[] InstanceData { get; }
Property Value
Type | Description |
---|---|
System.Byte[] |
IntervalLength
The lenght of intervals between execution
Declaration
public int IntervalLength { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 |
IntervalType
Interval type
Declaration
public ScheduledIntervalType IntervalType { get; set; }
Property Value
Type | Description |
---|---|
ScheduledIntervalType |
IsEnabled
If job is enabled for scheduling
Declaration
public bool IsEnabled { get; set; }
Property Value
Type | Description |
---|---|
System.Boolean |
IsRunning
Gets the running state for 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
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; }
Property Value
Type | Description |
---|---|
System.Boolean |
LastExecution
Date for last execution, System.DateTime.MinValue is identical with no last execution date
Declaration
public DateTime LastExecution { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
LastExecutionMessage
Informational message on last exection if any
Declaration
public string LastExecutionMessage { get; }
Property Value
Type | Description |
---|---|
System.String |
MethodName
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
Actual job name
Declaration
public string Name { get; set; }
Property Value
Type | Description |
---|---|
System.String |
NextExecution
Date for next execution, System.DateTime.MinValue is identical with no next execution date
Declaration
public DateTime NextExecution { get; set; }
Property Value
Type | Description |
---|---|
System.DateTime |
NextExecutionUTC
The original read-only UTC date for next execution
Declaration
public DateTime NextExecutionUTC { get; }
Property Value
Type | Description |
---|---|
System.DateTime |
PingTime
Gets the ping time.
Declaration
public TimeSpan PingTime { get; }
Property Value
Type | Description |
---|---|
System.TimeSpan | The ping time. |
SecondsAfterLastPing
Gets the ping time.
Declaration
public int SecondsAfterLastPing { get; set; }
Property Value
Type | Description |
---|---|
System.Int32 | The ping time. |
TypeName
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 EPiServer.Personalization
{
public class SubscriptionJob
...
the TypeName should be EPiServer.Personalization.SubscriptionJob
Methods
Delete()
Deletes the current job
Declaration
[Obsolete("Use IScheduledJobRepository to get/save/delete scheduled jobs")]
public void Delete()
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 |
|
Overrides
Exceptions
Type | Condition |
---|---|
System.NullReferenceException | The |
Execute(Boolean)
Execute the current job manually and add interval to NextExecute date
Declaration
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
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
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
IsJobRunning(Guid)
Get the running state for a job
Declaration
[Obsolete("Use IScheduledJobRepository to get/save/delete scheduled jobs")]
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 |
List()
Retrieves a list of all available jobs
Declaration
[Obsolete("Use IScheduledJobRepository to get/save/delete scheduled jobs")]
public static ScheduledJobCollection List()
Returns
Type | Description |
---|---|
ScheduledJobCollection |
ListRunningJobs()
Retrieves a list of all running jobs
Declaration
public static IList<ScheduledJobBase> ListRunningJobs()
Returns
Type | Description |
---|---|
System.Collections.Generic.IList<ScheduledJobBase> |
Load(Guid)
Load a job by id
Declaration
[Obsolete("Use IScheduledJobRepository to get/save/delete scheduled jobs")]
public static ScheduledJob Load(Guid id)
Parameters
Type | Name | Description |
---|---|---|
System.Guid | id | The id of the job |
Returns
Type | Description |
---|---|
ScheduledJob |
Load(String, String, String)
Load a job by method, type name and assembly
Declaration
[Obsolete("Use IScheduledJobRepository to get/save/delete scheduled jobs")]
public static ScheduledJob Load(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. |
LoadLog()
Loads log information for the ScheduledJob.
Declaration
[Obsolete("Use IScheduledJobStatusService to get execution log")]
public DataTable LoadLog()
Returns
Type | Description |
---|---|
System.Data.DataTable | A System.Data.DataTable containing log data where each row represents a log event. |
LoadNextScheduledJob()
Load the next job up for execution
Declaration
[Obsolete("Use IScheduledJobStatusService to get next scheduled job")]
public static ScheduledJob LoadNextScheduledJob()
Returns
Type | Description |
---|---|
ScheduledJob | A ScheduledJob instance if there is a waiting job, otherwise null. |
Save()
Saves job information or creates a new job
Declaration
[Obsolete("Use IScheduledJobRepository to get/save/delete scheduled jobs")]
public void Save()
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
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. |