예제 #1
0
        public async Task Start()
        {
            // Get all the failed ones!
            var failedRequests = _requestQueue.GetAll().Where(x => !x.Completed.HasValue);

            foreach (var request in failedRequests)
            {
                if (request.Type == RequestType.Movie)
                {
                    var movieRequest = await _movieRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _movieSender.Send(movieRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.TvShow)
                {
                    var tvRequest = await _tvRequestRepository.GetChild().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _tvSender.Send(tvRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.Album)
                {
                    var musicRequest = await _musicRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    var result = await _musicSender.Send(musicRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
            }
        }
예제 #2
0
        public async Task Execute(IJobExecutionContext job)
        {
            // Get all the failed ones!
            var failedRequests = _requestQueue.GetAll().Where(x => x.Completed == null);

            foreach (var request in failedRequests)
            {
                if (request.Type == RequestType.Movie)
                {
                    var movieRequest = await _movieRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (movieRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _movieSender.Send(movieRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.TvShow)
                {
                    var tvRequest = await _tvRequestRepository.GetChild().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (tvRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _tvSender.Send(tvRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
                if (request.Type == RequestType.Album)
                {
                    var musicRequest = await _musicRequestRepository.GetAll().FirstOrDefaultAsync(x => x.Id == request.RequestId);

                    if (musicRequest == null)
                    {
                        await _requestQueue.Delete(request);

                        await _requestQueue.SaveChangesAsync();

                        continue;
                    }
                    var result = await _musicSender.Send(musicRequest);

                    if (result.Success)
                    {
                        request.Completed = DateTime.UtcNow;
                        await _requestQueue.SaveChangesAsync();
                    }
                }
            }
        }