Exemple #1
0
        public async Task Run()
        {
            while (true)
            {
                try
                {
                    Console.WriteLine("Polling...");
                    var request = await _videoService.GetNextRequestAsync();

                    if (request != null && request.Id > 0)
                    {
                        Console.WriteLine("Request found: " + request.Id);

                        try
                        {
                            // process w/ youtube-dl
                            _youtubeService.ProcessVideoRequest(request);

                            // update to completed status
                            request.Status = VideoRequestStatus.Completed;
                            await _videoService.UpdateRequestStatusAsync(request);
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message + " " + ex.StackTrace);

                            request.Status = VideoRequestStatus.Error;
                            await _videoService.UpdateRequestStatusAsync(request);
                        }
                    }
                    else
                    {
                        Console.WriteLine("No requests found...");
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + " " + ex.StackTrace);
                }

                // sleep for 60 seconds, then re-poll
                Thread.Sleep(60000);
            }
            // poll for new messages
        }
Exemple #2
0
        protected override async Task ExecuteAsync(CancellationToken stoppingToken)
        {
            _logger.LogInformation("AVAS Running...");
            while (!stoppingToken.IsCancellationRequested)
            {
                try
                {
                    var request = await _videoService.GetNextRequestAsync();

                    if (request != null && request.Id > 0)
                    {
                        _logger.LogWarning("Request found: " + request.Id);

                        try
                        {
                            // process w/ youtube-dl
                            _youtubeService.ProcessVideoRequest(request);

                            // update to completed status
                            request.Status = VideoRequestStatus.Completed;
                            await _videoService.UpdateRequestStatusAsync(request);
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex, ex.Message);

                            request.Status = VideoRequestStatus.Error;
                            await _videoService.UpdateRequestStatusAsync(request);
                        }
                    }
                    else
                    {
                        _logger.LogWarning("No requests found...");
                    }
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, ex.Message);
                }

                // sleep for 60 seconds, then re-poll
                await Task.Delay(60000, stoppingToken);
            }
        }