コード例 #1
0
ファイル: JobService.cs プロジェクト: zpavic/MassTransit
        async Task Run <T>(ConsumerJobContext <T> jobContext, IJobFactory <T> jobFactory)
            where T : class
        {
            try
            {
                IPipe <JobContext <T> > pipe = Pipe.New <JobContext <T> >(cfg =>
                {
                    cfg.UseRetry(r =>
                    {
                        r.Ignore <TaskCanceledException>();
                        r.Ignore <OperationCanceledException>();
                        r.Interval(1, 1000);
                    });

                    cfg.UseExecuteAsync(context => context.NotifyStarted(_managementAddress));

                    cfg.UseInlineFilter(jobFactory.Execute);

                    cfg.UseExecuteAsync(context => context.NotifyCompleted());
                });

                await pipe.Send(jobContext).ConfigureAwait(false);
            }
            catch (TaskCanceledException)
            {
                await jobContext.NotifyCanceled("Task canceled").ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
                await jobContext.NotifyCanceled("Operation canceled").ConfigureAwait(false);
            }
            catch (Exception exception)
            {
                await jobContext.NotifyFaulted(exception).ConfigureAwait(false);
            }
            finally
            {
                jobContext.Dispose();
            }
        }
コード例 #2
0
 public Task NotifyCanceled(string reason = null)
 {
     return(_jobContext.NotifyCanceled(reason));
 }