本文整理汇总了C#中IJob.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# IJob.GetType方法的具体用法?C# IJob.GetType怎么用?C# IJob.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IJob
的用法示例。
在下文中一共展示了IJob.GetType方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: CreateDescriptor
/// <summary>
/// Tries to create a JobDescriptor for the given job.
/// </summary>
/// <param name="job">
/// The IJob object to create a descriptor for.
/// </param>
/// <returns>
/// An instance of JobDescriptor that describes the job.
/// </returns>
public JobDescriptor CreateDescriptor(IJob job)
{
if (null == job)
{
throw new ArgumentNullException("job");
}
JobSpec spec;
if (!typeToSpecMap.TryGetValue(job.GetType(), out spec))
{
throw new UnknownJobException(null, job.GetType().Name);
}
JobDescriptor descriptor = spec.Describe(job);
return descriptor;
}
示例3: ScheduleAsync
private Task<IJobId> ScheduleAsync(IJob job, Func<IBackgroundJobClient, JobDefinition, string, string> schedule)
{
var jobDefinition = _jobDefinitionService.GetJobDefinition(job.GetType());
var json = _jsonSerializer.Serialize(job);
var id = schedule(_backgroundJobClient, jobDefinition, json);
_log.Verbose($"Scheduled job '{id}' in Hangfire");
return Task.FromResult<IJobId>(new HangfireJobId(id));
}
示例4: ScheduleNowAsync
public async Task<IJobId> ScheduleNowAsync(IJob job, CancellationToken cancellationToken)
{
var jobDefinition = _jobDefinitionService.GetJobDefinition(job.GetType());
var json = _jsonSerializer.Serialize(job);
_log.Verbose(() => $"Executing job '{jobDefinition.Name}' v{jobDefinition.Version}: {json}");
// Don't schedule, just execute...
await _jobRunner.ExecuteAsync(jobDefinition.Name, jobDefinition.Version, json, cancellationToken).ConfigureAwait(false);
return JobId.New;
}
示例5: scheduleJob
/**
Método que pérmite calendarizar un nuevo job dentro de los cron del Sistema
**/
public static void scheduleJob(IJob jobToSchedule, String cronExpression)
{
JobDetailImpl jobDetail = new JobDetailImpl("Job_" + jobCounter, "Group_" + jobCounter, jobToSchedule.GetType());
CronTriggerImpl trigger = null;
DateTimeOffset? dateTimOffset = null;
if ( _scheduler == null)
{
initScheduler();
}
//Se crea el trigeer con el que se va a lanzar el job
trigger = new CronTriggerImpl("Trigger_" + jobCounter, "Group_" + jobCounter, cronExpression);
//Se agrega el calendarizador al scheduler
_scheduler.ScheduleJob(jobDetail, trigger);
//Se solicita el date Para el siguiente evento del scheduler
dateTimOffset = trigger.GetNextFireTimeUtc();
Console.WriteLine("Job Scheduled");
Console.WriteLine(jobDetail.FullName + " its about to be fired at " + dateTimOffset.Value );
jobCounter++;
}
示例6: JobTypeString
/// <summary>
/// Gets the string used when persisting the type of an <see cref="IJob"/> into a <see cref="JobRecord"/>.
/// </summary>
/// <param name="job">The job to get the type string from.</param>
/// <returns>A job type string.</returns>
public static string JobTypeString(IJob job)
{
if (job == null)
{
throw new ArgumentNullException("job", "job cannot be null.");
}
return JobTypeString(job.GetType());
}
示例7: InitializeJob
private bool InitializeJob(IJob job)
{
string jobName = job.GetType().Name;
Logger.Instance.LogFormat(LogType.Info, this, Resources.JobInitializeBegin, jobName);
try
{
if (!job.Initialize(_serviceProvider))
{
Logger.Instance.LogFormat(LogType.Warning, this, Resources.JobInitializeError, jobName);
return false;
}
Logger.Instance.LogFormat(LogType.Info, this, Resources.JobInitializeSuccess, jobName);
return true;
}
catch (Exception ex)
{
Logger.Instance.LogFormat(LogType.Error, this, Resources.JobGenericError, jobName, ex.Message);
Logger.Instance.LogException(this, ex);
return false;
}
}
示例8: 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);
}
}
示例9: RunJob
private void RunJob(IJobContext context, Operation operation, IJob job)
{
if (job.IsAsync)
{
Logger.Instance.LogFormat(LogType.Info, this, Resources.JobExecuteAsyncStart, job.GetType().Name, context.Phase);
ThreadPool.QueueUserWorkItem(o => RunJobCore(context, operation, job));
}
else
{
Logger.Instance.LogFormat(LogType.Info, this, Resources.JobExecuteSyncStart, job.GetType().Name, context.Phase);
RunJobCore(context, operation, job);
}
}
示例10: ScheduleAsync
public Task<IJobId> ScheduleAsync(IJob job, TimeSpan delay, CancellationToken cancellationToken)
{
_log.Warning($"Instant scheduling configured, executing job '{job.GetType().PrettyPrint()}' NOW! Instead of in '{delay}'");
return ScheduleNowAsync(job, cancellationToken);
}
示例11: ScheduledJobRecord
public ScheduledJobRecord(IJob job)
{
JobKey = JobStatus.GetKey(job.GetType());
}
示例12: ReturnJob
/// <summary>
/// Allows the the job factory to destroy/cleanup the job if needed.
/// </summary>
/// <param name="job"></param>
public void ReturnJob(IJob job)
{
this.logger.DebugFormat("Releasing the component for job '{0}'.", job.GetType());
this.container.Release(job);
}
示例13: RunJobAsync
async Task RunJobAsync(IJob job, CancellationToken cancellationToken)
{
var jobtype = job.GetType()
.FullName;
job.Log += InvokeLog;
job.ExceptionThrown += InvokeExceptionThrown;
try
{
InvokeLog($"\t\tJob {jobtype} {STARTED}");
await job.RunAsync(cancellationToken);
}
catch (OperationCanceledException)
{
InvokeLog($"\t\tJob {jobtype} {CANCELLED}");
}
catch (Exception exception)
{
InvokeLog($"\t\tJob {jobtype} {ERRORED}");
InvokeLog($"{jobtype} Exception{NewLine}{exception.ToText()}");
InvokeExceptionThrown(job, new JobExceptionThrownEventArguments { Exception = exception, Job = job });
}
finally
{
job.ExceptionThrown -= InvokeExceptionThrown;
job.Log -= InvokeLog;
InvokeLog($"\t\tJob {jobtype} {FINISHED}");
job.Dispose();
}
}
示例14: 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);
}
}