Last active
July 3, 2018 14:30
-
-
Save jraps20/2145b6b1e01c84e5faba8cbe24d78fd1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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