private async Task CheckStuckSongAsync(FalconFppdStatusDto status, string previousSecondsPlayed, string previousSecondsRemaining) { if (status.Mode_Name.IsRemoteInstance() || status.Current_Song.IsNull()) { return; } if (previousSecondsPlayed == status.Seconds_Played || previousSecondsRemaining == status.Seconds_Remaining) { await _twitterService.PostTweetAlarmAsync(ExceptionMessage.FppFrozen); } }
public async Task ExecuteVitalsWorkerAsync(CancellationToken stoppingToken) { string previousSecondsPlayed = string.Empty; string previousSecondsRemaining = string.Empty; while (stoppingToken.IsCancellationRequested == false) { ResetAlarmCount(); try { FalconFppdMultiSyncSystemsDto syncStatus = await _fppClient.GetMultiSyncStatusAsync(_appSettings.FppHosts[0]); foreach (var fppInstance in syncStatus.Systems) { _logger.LogInformation($"Checking vitals for {fppInstance.Hostname} ({fppInstance.Address})"); FalconFppdStatusDto falconFppdStatus = await _fppClient.GetFppdStatusAsync(fppInstance.Address); if (falconFppdStatus.IsNull()) { _logger.LogError(ExceptionMessage.FppOffline); continue; } await CheckCpuTemperatureAsync(falconFppdStatus); await CheckStuckSongAsync(falconFppdStatus, previousSecondsPlayed, previousSecondsRemaining); if (falconFppdStatus.Mode_Name.IsRemoteInstance() == false) { previousSecondsPlayed = falconFppdStatus.Seconds_Played; previousSecondsRemaining = falconFppdStatus.Seconds_Remaining; } } } catch (TwitterException ex) { _logger.LogError(ex, ex.Message); } catch (Exception ex) { _logger.LogError(ex, ex.Message); } await Task.Delay(TimeSpan.FromSeconds(DelaySeconds.Long), stoppingToken); } }
public async Task ExecuteCurrentSongWorkerAsync(CancellationToken stoppingToken) { string previousSong = string.Empty; while (stoppingToken.IsCancellationRequested == false) { await Task.Delay(TimeSpan.FromSeconds(DelaySeconds.Short), stoppingToken); try { FalconFppdStatusDto fppStatus = await _fppClient.GetFppdStatusAsync(_appSettings.FppHosts[0]); if (fppStatus.Mode_Name.IsRemoteInstance()) { _logger.LogWarning("This is remote instance of FPP. Exiting"); break; } if (fppStatus.Current_Song.IsNullOrEmpty() || previousSong == fppStatus.Current_Song) { continue; } FalconMediaMetaDto falconMediaMeta = await _fppClient.GetCurrentSongMetaDataAsync(fppStatus.Current_Song); if (falconMediaMeta.IsNull()) { continue; } string songTitle = string.IsNullOrEmpty(falconMediaMeta.Format.Tags.Title) ? fppStatus.Current_Song.GetSongNameFromFileName() : falconMediaMeta.Format.Tags.Title; await _twitterService.PostCurrentSongAsync(songTitle, falconMediaMeta.Format.Tags.Artist); previousSong = fppStatus.Current_Song; } catch (TwitterException ex) { _logger.LogError(ex.InnerException.ToString(), ex.Message); await Task.Delay(TimeSpan.FromHours(6), stoppingToken); } catch (Exception ex) { _logger.LogError(ex.InnerException.ToString(), ex.Message); } } }