本文整理汇总了C#中IJob.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# IJob.Execute方法的具体用法?C# IJob.Execute怎么用?C# IJob.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJob
的用法示例。
在下文中一共展示了IJob.Execute方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetWork
public Task GetWork(IJob job)
{
Task task;
try
{
task = job.Execute();
}
catch (Exception e)
{
QuietLog.LogHandledException(e);
return new Task(() => {}); // returning dummy task so the job scheduler doesn't see errors
}
// wrapping the task inside an outer task which will continue with an error handler.
return CreateWrappingContinuingTask(task, t =>
{
if (t.IsCanceled)
{
Debug.WriteLine("Background Task Canceled: " + job.GetType());
}
else if (t.IsFaulted)
{
Debug.WriteLine("Background Task Faulted: " + job.GetType());
QuietLog.LogHandledException(task.Exception);
}
// else happiness
}, TaskContinuationOptions.ExecuteSynchronously);
}
示例2: Execute
public async Task Execute(IJob job)
{
var source = new CancellationTokenSource(_timeout);
var cancellation = new CancellationToken();
var task = Task.Factory.StartNew(() => job.Execute(source.Token), source.Token);
var timeout = Task.Delay(_timeout, cancellation);
if (await Task.WhenAny(task, timeout) == task)
{
await task;
}
else
{
var marker = new TaskCompletionSource<object>();
marker.SetException(new TimeoutException("Timed out after " + _timeout));
await marker.Task;
}
}
示例3: GetWork
// Returns a task with the work to do if work is available to do and another web server
// in the web farm isn't already doing it.
public Task GetWork(IJob job)
{
if (job == null)
{
throw new ArgumentNullException("job");
}
var unitOfWork = ReserveWork(WebServerWorkerId, job);
if (unitOfWork == null)
{
return null;
}
Task task = null;
try
{
task = job.Execute();
}
catch (Exception e)
{
task = new Task(() => { throw e; });
}
task.ContinueWith(c =>
{
if (c.IsFaulted)
{
unitOfWork.Fail(c.Exception.GetBaseException());
}
else
{
unitOfWork.Complete();
}
});
return task;
}
示例4: RunJobCore
private void RunJobCore(IJobContext context, Operation operation, IJob job)
{
try
{
job.Execute(context, operation);
Logger.Instance.LogFormat(LogType.Trace, this, Resources.JobExecuteFinished, job.GetType().Name);
}
catch (Exception ex)
{
string message = (job.IsAsync) ? Properties.Resources.JobExecuteAsyncFailed : Properties.Resources.JobExecuteSyncFailed;
Logger.Instance.LogFormat(LogType.Warning, this, string.Format(message, job.GetType().Name));
Logger.Instance.LogException(this, ex);
}
}
示例5: Execute
/// <summary>
/// Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
/// fires that is associated with the <see cref="T:Quartz.IJob" />.
/// </summary>
/// <remarks>
/// The implementation may wish to set a result object on the
/// JobExecutionContext before this method exits. The result itself
/// is meaningless to Quartz, but may be informative to
/// <see cref="T:Quartz.IJobListener" />s or
/// <see cref="T:Quartz.ITriggerListener" />s that are watching the job's
/// execution.
/// </remarks>
/// <param name="context">The execution context.</param>
/// <exception cref="SchedulerConfigException">Job cannot be instantiated.</exception>
public void Execute(IJobExecutionContext context)
{
var childContainer = unityContainer.CreateChildContainer();
try
{
RunningJob = (IJob)childContainer.Resolve(bundle.JobDetail.JobType);
RunningJob.Execute(context);
}
catch (JobExecutionException)
{
throw;
}
catch (Exception ex)
{
throw new JobExecutionException(string.Format(CultureInfo.InvariantCulture,
"Failed to execute Job '{0}' of type '{1}'",
bundle.JobDetail.Key, bundle.JobDetail.JobType), ex);
}
finally
{
RunningJob = null;
childContainer.Dispose();
}
}
示例6: CreateJobAction
/// <summary>
/// Action creation helper.
/// Given a job, job parameters and a job execution,
/// will wrap the execution of the job into a <see cref="System.Action"/>.
/// </summary>
/// <param name="job">the job to execute</param>
/// <param name="jobParameters">the job parameters</param>
/// <param name="jobExecution">the job execution</param>
/// <returns></returns>
private static Action CreateJobAction(IJob job, JobParameters jobParameters, JobExecution jobExecution)
{
Action jobAction = (() =>
{
try
{
Logger.Info("Job: [{0} ] launched with the following parameters:[{1}]",job,jobParameters);
job.Execute(jobExecution);
Logger.Info("Job: [{0}] completed with the following parameters:[{1}] and the following status: [{2}]",
job,jobParameters,jobExecution.Status);
}
catch (Exception exception)
{
Logger.Info("Job: [{0}] failed unexpectedly and fatally with the following parameters: [{1}]",job,exception);
throw;
}
});
return jobAction;
}
示例7: GetWork
public Task GetWork(IJob job)
{
return job.Execute();
}
示例8: RunJob
private void RunJob(IJob job)
{
try
{
DateTime start = DateTime.Now;
var newJobs = job.Execute();
DateTime end = DateTime.Now;
logger.Info("{0} finished in {2} s. and returned {1} new jobs.", job.Name, newJobs.Count, (end-start).TotalSeconds);
foreach (var newJob in newJobs)
{
AddJob(newJob);
}
}
catch (Exception exp2)
{
logger.Error(exp2, "{0} failed while executing.", job.Name);
}
}
示例9: RunJobCore
private void RunJobCore(IJobContext context, Operation operation, IJob job)
{
// Run the job. If the job fails, ignore that exception as well but log it too!
try
{
job.Execute(context, operation);
}
catch (Exception ex)
{
string message = (job.IsAsync) ? Properties.Resources.JobExecuteAsyncFailed : Properties.Resources.JobExecuteSyncFailed;
// Be careful when processing the jobs, we don't want a malicious job to terminate the process!
Logger.Instance.LogFormat(LogType.Warning, this, string.Format(message, job.GetType().Name));
Logger.Instance.LogException(this, ex);
}
}
示例10: UpdateUI
private void UpdateUI(IJob job)
{
job.Execute(this);
}
示例11: Execute
/// <summary>
/// Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
/// fires that is associated with the <see cref="T:Quartz.IJob" />.
/// </summary>
/// <remarks>
/// The implementation may wish to set a result object on the
/// JobExecutionContext before this method exits. The result itself
/// is meaningless to Quartz, but may be informative to
/// <see cref="T:Quartz.IJobListener" />s or
/// <see cref="T:Quartz.ITriggerListener" />s that are watching the job's
/// execution.
/// </remarks>
/// <param name="context">The execution context.</param>
/// <exception cref="SchedulerConfigException">Job cannot be instantiated.</exception>
public void Execute(IJobExecutionContext context)
{
var childContainer = _unityContainer.CreateChildContainer();
try
{
try
{
RunningJob = (IJob)childContainer.Resolve(Bundle.JobDetail.JobType);
}
catch (Exception ex)
{
throw new JobExecutionException(string.Format("Failed to instantiate Job '{0}' of type '{1}'",
Bundle.JobDetail.Key, Bundle.JobDetail.JobType), ex);
}
RunningJob.Execute(context);
}
catch (JobExecutionException)
{
throw;
}
catch (Exception ex)
{
throw new JobExecutionException(
string.Format("Unhandled exception in job '{0}'. {1}", Bundle.JobDetail.Key, ex.Message), ex);
}
finally
{
ClearJob();
childContainer.Dispose();
}
}
示例12: ExecuteJob
internal bool ExecuteJob(IJob job, out Exception ex)
{
bool success = false;
ex = null;
try
{
// Execute the job, with a timeout if necessary.
int timeout = job.Timeout < 0 ? 60000 : job.Timeout;
if (timeout > 0)
{
this.logger.Info("Worker {0} ({1}) is executing job '{2}' with timeout {3}.", this.name, this.id, job.Name, job.Timeout);
new Action(job.Execute).InvokeWithTimeout(timeout);
}
else
{
this.logger.Info("Worker {0} ({1}) is executing job '{2}' with no timeout.", this.name, this.id, job.Name);
job.Execute();
}
success = true;
}
catch (Exception tx)
{
ex = tx;
}
return success;
}
示例13: Execute
/// <summary>
/// Called by the <see cref="T:Quartz.IScheduler" /> when a <see cref="T:Quartz.ITrigger" />
/// fires that is associated with the <see cref="T:Quartz.IJob" />.
/// </summary>
/// <remarks>
/// The implementation may wish to set a result object on the
/// JobExecutionContext before this method exits. The result itself
/// is meaningless to Quartz, but may be informative to
/// <see cref="T:Quartz.IJobListener" />s or
/// <see cref="T:Quartz.ITriggerListener" />s that are watching the job's
/// execution.
/// </remarks>
/// <param name="context">The execution context.</param>
/// <exception cref="SchedulerConfigException">Job cannot be instantiated.</exception>
public void Execute(IJobExecutionContext context)
{
var scope = _lifetimeScope.BeginLifetimeScope(_scopeName);
try
{
RunningJob = CreateJob(scope);
RunningJob.Execute(context);
}
catch (Exception ex)
{
throw new SchedulerConfigException(string.Format(CultureInfo.InvariantCulture,
"Failed to instantiate Job '{0}' of type '{1}'",
_bundle.JobDetail.Key, _bundle.JobDetail.JobType), ex);
}
finally
{
RunningJob = null;
scope.Dispose();
}
}