示例#1
0
        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 NotifyFaulted(Exception exception)
 {
     return(_jobContext.NotifyFaulted(exception));
 }