World is now on Opti ID! Learn more
AI OnAI Off
World is now on Opti ID! Learn more
1) You can trigger your job by following code (you need to obtain job Id for that - see point 2):
ScheduledJob jobInstance;
if (job.InstanceId != Guid.Empty)
{
jobInstance = ScheduledJob.Load(job.InstanceId);
}
else
{
jobInstance = new ScheduledJob
{
IntervalType = ScheduledIntervalType.Days,
IsEnabled = false,
Name = job.Name,
MethodName = "Execute",
TypeName = job.TypeName,
AssemblyName = job.AssemblyName,
IsStaticMethod = true
};
if (jobInstance.NextExecution == DateTime.MinValue)
{
jobInstance.NextExecution = DateTime.Today;
}
jobInstance.Save();
}
if (jobInstance != null)
{
jobInstance.ExecuteManually();
}
2) For checking whether job is running - you have to get job Id somehow.
var isRunning = EPiServer.DataAbstraction.ScheduledJob.IsJobRunning(job.ID);
To get job id you need to know type and probably assembly as well (to avoid collisions):
var job = ScheduledJob.List().FirstOrDefault(j => j.TypeName == typeof(YourJobTypeName) && j.AssemblyName == "YourAssemblyName");
You have to create new ScheduledJob instances for `jobs` (or actually `plugins`) that has not been executed yet - therefore -> there is no job instance generated for those ones.
Some question about scheduled jobs:
1. Is it possible to trigger scheduled job from code (programatically)?
2. Is it possible to track whether specific job is running at the moment.