Don't miss out Virtual Happy Hour this Friday (April 26).

Try our conversational search powered by Generative AI!

Scheduled Jobs

Vote:
 

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.

#82937
Mar 21, 2014 14:34
Vote:
 

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");

    

#82941
Mar 21, 2014 15:25
Vote:
 

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.

#82948
Mar 21, 2014 17:45
Vote:
 

You can check some sample code here: https://github.com/valdisiljuconoks/TechFellow.ScheduledJobOverview

#82949
Mar 21, 2014 17:45
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.