sign out events by THEIR ids, not YOURS 🤦

This commit is contained in:
Adam R. Grey 2021-12-02 07:30:04 -05:00
parent 7afdef665a
commit d88ee494fa

View File

@ -26,6 +26,7 @@ namespace director
private static readonly AutoResetEvent _signal = new AutoResetEvent(false); private static readonly AutoResetEvent _signal = new AutoResetEvent(false);
private const int concurrentWorkers = 5; private const int concurrentWorkers = 5;
private static readonly ConcurrentBag<Guid> workerIds = new ConcurrentBag<Guid>(); private static readonly ConcurrentBag<Guid> workerIds = new ConcurrentBag<Guid>();
private static readonly ConcurrentDictionary<string, Guid> occurenceHandlers = new ConcurrentDictionary<string, Guid>();
static void Main(string[] args) static void Main(string[] args)
{ {
if (!File.Exists("appsettings.json")) if (!File.Exists("appsettings.json"))
@ -92,29 +93,18 @@ namespace director
if ((s.Showtime - TimeSpan.FromDays(1)) - DateTime.Now <= calendarNaptime) if ((s.Showtime - TimeSpan.FromDays(1)) - DateTime.Now <= calendarNaptime)
{ {
var copy = JsonConvert.DeserializeObject<schedulable.Scheduled>(JsonConvert.SerializeObject(s)); var copy = JsonConvert.DeserializeObject<schedulable.Scheduled>(JsonConvert.SerializeObject(s));
if(!occurenceHandlers.ContainsKey(copy.Occurrence._event.Uid) || !workerIds.Contains(occurenceHandlers[copy.Occurrence._event.Uid]))
{
workQueue.Enqueue(copy); workQueue.Enqueue(copy);
_signal.Set(); _signal.Set();
} }
else
{
Console.WriteLine($"calendars checked, looks like event {copy.Occurrence._event.Uid} thing is handled");
}
}
} }
Console.WriteLine("calendars checked"); Console.WriteLine("calendars checked");
// #if (DEBUG)
// //if(true)
// {
// Console.WriteLine("debug test");
// var psuedo = new schedulable.Scheduled();
// psuedo.Showtime = DateTime.Now + TimeSpan.FromMinutes(30);
// // foreach(var a in scratch.agenda){
// // Console.WriteLine(a.Occurrence._event.Summary);
// // }
// var partiallyCopiable = scratch.agenda?.First(a => a.Occurrence._event.Summary == "Good Morning, Phyrexia (in the morning)!");
// psuedo.Occurrence = partiallyCopiable.Occurrence;
// psuedo.Occurrence.OccurrenceStart = psuedo.Showtime;
// psuedo.Occurrence.OccurrenceEnd = psuedo.Showtime;
// workQueue.Enqueue(psuedo);
// _signal.Set();
// }
// #endif
} }
private static async Task checkCalendar(string calendarUri) private static async Task checkCalendar(string calendarUri)
@ -164,7 +154,8 @@ namespace director
continue; continue;
} }
todo.HandledBy = threadId; todo.HandledBy = threadId;
Console.WriteLine($"signing it out, {todo.HandledBy}"); occurenceHandlers[todo.Occurrence._event.Uid] = threadId;
Console.WriteLine($"signing it out. i'm {todo.HandledBy}, handling {todo.Occurrence._event.Uid}");
todo.Configuration = findConfig(todo.Occurrence.CalendarSourceName, todo.Occurrence._event.Summary); todo.Configuration = findConfig(todo.Occurrence.CalendarSourceName, todo.Occurrence._event.Summary);
if (todo.Configuration == null) if (todo.Configuration == null)