| | | 1 | | using Hangfire; |
| | | 2 | | |
| | | 3 | | namespace Services.BackgroundJobsServices; |
| | | 4 | | |
| | | 5 | | public interface ITransactionJobRetryScheduler |
| | | 6 | | { |
| | | 7 | | void ScheduleScheduledRetry(int scheduleId, string jobType, int retryAttempt); |
| | | 8 | | void ScheduleManualRetry(int ozonClientId, int daysBack, string jobType, string? signalRJobId, int retryAttempt); |
| | | 9 | | } |
| | | 10 | | |
| | | 11 | | public class TransactionJobRetryScheduler : ITransactionJobRetryScheduler |
| | | 12 | | { |
| | | 13 | | private readonly IBackgroundJobClient _backgroundJobClient; |
| | | 14 | | |
| | 0 | 15 | | public TransactionJobRetryScheduler(IBackgroundJobClient backgroundJobClient) |
| | | 16 | | { |
| | 0 | 17 | | _backgroundJobClient = backgroundJobClient; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public void ScheduleScheduledRetry(int scheduleId, string jobType, int retryAttempt) |
| | | 21 | | { |
| | 0 | 22 | | var delay = TransactionJobRetryPolicy.GetDelayForAttempt(retryAttempt); |
| | | 23 | | |
| | 0 | 24 | | if (string.Equals(jobType, "CustomerReturn", StringComparison.OrdinalIgnoreCase)) |
| | | 25 | | { |
| | 0 | 26 | | _backgroundJobClient.Schedule<IAutomatedTransactionProcessingService>( |
| | 0 | 27 | | service => service.ProcessCustomerReturnScheduledRetryAsync(scheduleId, retryAttempt, CancellationToken. |
| | 0 | 28 | | delay); |
| | 0 | 29 | | return; |
| | | 30 | | } |
| | | 31 | | |
| | 0 | 32 | | _backgroundJobClient.Schedule<IAutomatedTransactionProcessingService>( |
| | 0 | 33 | | service => service.ProcessShippedToCommissionerScheduledRetryAsync(scheduleId, retryAttempt, CancellationTok |
| | 0 | 34 | | delay); |
| | 0 | 35 | | } |
| | | 36 | | |
| | | 37 | | public void ScheduleManualRetry(int ozonClientId, int daysBack, string jobType, string? signalRJobId, int retryAttem |
| | | 38 | | { |
| | 0 | 39 | | var delay = TransactionJobRetryPolicy.GetDelayForAttempt(retryAttempt); |
| | 0 | 40 | | var jobId = string.IsNullOrWhiteSpace(signalRJobId) |
| | 0 | 41 | | ? $"manual-retry-{retryAttempt}-{Guid.NewGuid():N}"[..24] |
| | 0 | 42 | | : signalRJobId.Trim(); |
| | 0 | 43 | | if (string.Equals(jobType, "CustomerReturn", StringComparison.OrdinalIgnoreCase)) |
| | | 44 | | { |
| | 0 | 45 | | _backgroundJobClient.Schedule<IAutomatedTransactionProcessingService>( |
| | 0 | 46 | | service => service.ProcessCustomerReturnManualRetryAsync( |
| | 0 | 47 | | ozonClientId, daysBack, jobId, retryAttempt, CancellationToken.None), |
| | 0 | 48 | | delay); |
| | 0 | 49 | | return; |
| | | 50 | | } |
| | | 51 | | |
| | 0 | 52 | | _backgroundJobClient.Schedule<IAutomatedTransactionProcessingService>( |
| | 0 | 53 | | service => service.ProcessShippedToCommissionerManualRetryAsync( |
| | 0 | 54 | | ozonClientId, daysBack, jobId, retryAttempt, CancellationToken.None), |
| | 0 | 55 | | delay); |
| | 0 | 56 | | } |
| | | 57 | | } |