Skip to content

Instantly share code, notes, and snippets.

@jraps20
Last active July 3, 2018 14:30
Show Gist options
  • Save jraps20/2145b6b1e01c84e5faba8cbe24d78fd1 to your computer and use it in GitHub Desktop.
Save jraps20/2145b6b1e01c84e5faba8cbe24d78fd1 to your computer and use it in GitHub Desktop.
using Quartz;
using Sitecron.SitecronSettings;
public abstract class SiteCronBase : IJob
{
private DateTime _lastLogEntry;
protected abstract void Run(IJobExecutionContext args);
public void Execute(IJobExecutionContext context)
{
var startExecution = DateTime.Now;
_lastLogEntry = DateTime.Now;
Run(context);
_lastLogEntry = startExecution;
WriteLogLine(context, "Job completed in elapsed time shown.");
}
protected void WriteLogLine(IJobExecutionContext context, string value)
{
var log = context.JobDetail.JobDataMap.GetString(SitecronConstants.ParamNames.SitecronJobLogData);
var line = $"{DateTime.Now.ToUniversalTime()} - - {value}, Elapsed time since last step: {(DateTime.Now - _lastLogEntry).TotalSeconds} seconds";
Log.Info(line, this);
log = log + "\r\n" + line;
context.JobDetail.JobDataMap.Put(SitecronConstants.ParamNames.SitecronJobLogData, log);
_lastLogEntry = DateTime.Now;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment