public async Task <JobHandle> StartJob <T>(ConsumeContext <StartJob> context, T job, IPipe <ConsumeContext <T> > jobPipe, TimeSpan timeout) where T : class { var startJob = context.Message; if (_jobs.ContainsKey(startJob.JobId)) { throw new JobAlreadyExistsException(startJob.JobId); } var jobContext = new ConsumeJobContext <T>(context, InstanceAddress, startJob.JobId, startJob.AttemptId, startJob.RetryAttempt, job, timeout); LogContext.Debug?.Log("Executing job: {JobType} {JobId} ({RetryAttempt})", TypeMetadataCache <T> .ShortName, startJob.JobId, startJob.RetryAttempt); ConsumeContext <T> jobConsumeContext = new MessageConsumeContext <T>(context, job); jobConsumeContext.AddOrUpdatePayload <JobContext <T> >(() => jobContext, existing => jobContext); var jobTask = jobPipe.Send(jobConsumeContext); var jobHandle = new ConsumerJobHandle <T>(jobContext, jobTask); Add(jobHandle); return(jobHandle); }
public ConsumerJobHandle(ConsumeJobContext <T> context, Task task) { _context = context; _task = task; }