mirror of
https://github.com/9ParsonsB/Pulsar.git
synced 2025-12-16 04:44:56 +01:00
Expose core error logger to plugins and report custom criteria errors (#78)
* Expose core error logger to plugins and report custom criteria errors Fixes #77 This adds an error logging method on the IObservatoryCore interface that writes the exception details to ObservatoryCore's central error log (found in `${Documents}/ObservatoryErrorLog.txt`). In addition, added a timestamp to each error log. Also updates the Explorer to report Custom Criteria file load errors and execution errors to the log. Also updates HeraldNotifier to report CacheIndex.json parse failures to the error log as well. * Expand debugging/error logging in Herald; cleanup empty mp3 files Herald crashes if attempting to play 0-byte mp3s so if detected, delete, re-request (empty files can occur in some azure failure cases (ie. out of quota). Trap and log errors in other places in HeraldQueue to avoid hard crashes due to weird and wonderful unexpected stuff.
This commit is contained in:
@@ -4,6 +4,8 @@ using System.Threading.Tasks;
|
||||
using System.Linq;
|
||||
using NetCoreAudio;
|
||||
using System.Threading;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace Observatory.Herald
|
||||
{
|
||||
@@ -17,13 +19,15 @@ namespace Observatory.Herald
|
||||
private byte volume;
|
||||
private SpeechRequestManager speechManager;
|
||||
private Player audioPlayer;
|
||||
|
||||
public HeraldQueue(SpeechRequestManager speechManager)
|
||||
private Action<Exception, String> ErrorLogger;
|
||||
|
||||
public HeraldQueue(SpeechRequestManager speechManager, Action<Exception, String> errorLogger)
|
||||
{
|
||||
this.speechManager = speechManager;
|
||||
processing = false;
|
||||
notifications = new();
|
||||
audioPlayer = new();
|
||||
ErrorLogger = errorLogger;
|
||||
}
|
||||
|
||||
|
||||
@@ -55,37 +59,48 @@ namespace Observatory.Herald
|
||||
|
||||
private void ProcessQueue()
|
||||
{
|
||||
|
||||
while (notifications.Any())
|
||||
|
||||
NotificationArgs notification = null;
|
||||
try
|
||||
{
|
||||
audioPlayer.SetVolume(volume).Wait();
|
||||
var notification = notifications.Dequeue();
|
||||
|
||||
Task<string>[] audioRequestTasks = new Task<string> [2];
|
||||
|
||||
|
||||
if (string.IsNullOrWhiteSpace(notification.TitleSsml))
|
||||
while (notifications.Any())
|
||||
{
|
||||
audioRequestTasks[0] = RetrieveAudioToFile(notification.Title);
|
||||
}
|
||||
else
|
||||
{
|
||||
audioRequestTasks[0] = RetrieveAudioSsmlToFile(notification.TitleSsml);
|
||||
}
|
||||
audioPlayer.SetVolume(volume).Wait();
|
||||
notification = notifications.Dequeue();
|
||||
Debug.WriteLine("Processing notification: {0} - {1}", notification.Title, notification.Detail);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(notification.DetailSsml))
|
||||
{
|
||||
audioRequestTasks[1] = RetrieveAudioToFile(notification.Detail);
|
||||
}
|
||||
else
|
||||
{
|
||||
audioRequestTasks[1] = RetrieveAudioSsmlToFile(notification.DetailSsml);
|
||||
}
|
||||
Task<string>[] audioRequestTasks = new Task<string>[2];
|
||||
|
||||
PlayAudioRequestsSequentially(audioRequestTasks);
|
||||
if (string.IsNullOrWhiteSpace(notification.TitleSsml))
|
||||
{
|
||||
audioRequestTasks[0] = RetrieveAudioToFile(notification.Title);
|
||||
}
|
||||
else
|
||||
{
|
||||
audioRequestTasks[0] = RetrieveAudioSsmlToFile(notification.TitleSsml);
|
||||
}
|
||||
|
||||
if (string.IsNullOrWhiteSpace(notification.DetailSsml))
|
||||
{
|
||||
audioRequestTasks[1] = RetrieveAudioToFile(notification.Detail);
|
||||
}
|
||||
else
|
||||
{
|
||||
audioRequestTasks[1] = RetrieveAudioSsmlToFile(notification.DetailSsml);
|
||||
}
|
||||
|
||||
PlayAudioRequestsSequentially(audioRequestTasks);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Failed to fetch/play notification: {notification?.Title} - {notification?.Detail}");
|
||||
ErrorLogger(ex, "while retrieving and playing audio for a notification");
|
||||
}
|
||||
finally
|
||||
{
|
||||
processing = false;
|
||||
}
|
||||
|
||||
processing = false;
|
||||
}
|
||||
|
||||
private async Task<string> RetrieveAudioToFile(string text)
|
||||
@@ -103,7 +118,15 @@ namespace Observatory.Herald
|
||||
foreach (var request in requestTasks)
|
||||
{
|
||||
string file = request.Result;
|
||||
audioPlayer.Play(file).Wait();
|
||||
try
|
||||
{
|
||||
Debug.WriteLine($"Playing audio file: {file}");
|
||||
audioPlayer.Play(file).Wait();
|
||||
} catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"Failed to play {file}: {ex.Message}");
|
||||
ErrorLogger(ex, $"while playing: {file}");
|
||||
}
|
||||
|
||||
while (audioPlayer.Playing)
|
||||
Thread.Sleep(50);
|
||||
|
||||
Reference in New Issue
Block a user