Skip to content

Commit

Permalink
CU-3wen6jw added logic to schedule permission matrix update
Browse files Browse the repository at this point in the history
  • Loading branch information
ucswift committed Aug 29, 2024
1 parent 96855a9 commit d3e383b
Show file tree
Hide file tree
Showing 17 changed files with 237 additions and 56 deletions.
2 changes: 2 additions & 0 deletions Core/Resgrid.Config/ServiceBusConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public static class ServiceBusConfig
public static string AuditQueueName = "audittest";
public static string UnitLoactionQueueName = "unitlocationtest";
public static string PersonnelLoactionQueueName = "personnellocationtest";
public static string SecurityRefreshQueueName = "securityrefreshtest";
#else
public static string CallBroadcastQueueName = "callbroadcast";
public static string MessageBroadcastQueueName = "messagebroadcast";
Expand All @@ -27,6 +28,7 @@ public static class ServiceBusConfig
public static string AuditQueueName = "audit";
public static string UnitLoactionQueueName = "unitlocation";
public static string PersonnelLoactionQueueName = "personnellocation";
public static string SecurityRefreshQueueName = "securityrefresh";
#endif

#region Azure Service Bus Values
Expand Down
5 changes: 0 additions & 5 deletions Core/Resgrid.Framework/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,8 @@ public static void Initialize(string key)
o.MinimumBreadcrumbLevel = LogEventLevel.Debug;
o.MinimumEventLevel = LogEventLevel.Error;
o.Dsn = dsn;
o.AttachStacktrace = true;
o.SendDefaultPii = true;
o.AutoSessionTracking = true;
o.TracesSampleRate = ExternalErrorConfig.SentryPerfSampleRate;
o.Environment = ExternalErrorConfig.Environment;
o.Release = Assembly.GetEntryAssembly().GetName().Version.ToString();
o.ProfilesSampleRate = 0.0;
}).CreateLogger();
}
else
Expand Down
23 changes: 23 additions & 0 deletions Core/Resgrid.Model/Events/SecurityRefreshEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using ProtoBuf;
using System;

namespace Resgrid.Model.Events
{
[ProtoContract]
public class SecurityRefreshEvent
{
[ProtoMember(1)]
public string EventId { get; set; }

[ProtoMember(2)]
public int DepartmentId { get; set; }

[ProtoMember(3)]
public SecurityCacheTypes Type { get; set; }

public SecurityRefreshEvent()
{
EventId = Guid.NewGuid().ToString();
}
}
}
1 change: 1 addition & 0 deletions Core/Resgrid.Model/Providers/IOutboundQueueProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public interface IOutboundQueueProvider
Task<bool> EnqueueShiftNotification(ShiftQueueItem shiftQueueItem);
Task<bool> EnqueueDistributionList(DistributionListQueueItem distributionListQueue);
Task<bool> EnqueueAuditEvent(AuditEvent auditEvent);
Task<bool> EnqueueSecurityRefreshEvent(SecurityRefreshEvent securityRefreshEvent);
}
}
2 changes: 1 addition & 1 deletion Core/Resgrid.Model/Resgrid.Model.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
<PackageReference Include="GeoCoordinate.NetCore" Version="1.0.0.1" />
<PackageReference Include="GeoJSON.Net" Version="1.2.19" />
<PackageReference Include="Microsoft.AspNetCore.Identity" Version="2.2.0" />
<PackageReference Include="MimeKit" Version="4.4.0" />
<PackageReference Include="MimeKit" Version="4.7.1" />
<PackageReference Include="MongoDB.Driver" Version="2.24.0" />
<PackageReference Include="protobuf-net" Version="3.2.30" />
<PackageReference Include="Stripe.net" Version="45.1.0" />
Expand Down
6 changes: 6 additions & 0 deletions Providers/Resgrid.Providers.Bus.Rabbit/RabbitConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,12 @@ public static bool VerifyAndCreateClients()
autoDelete: false,
arguments: null);

channel.QueueDeclare(queue: SetQueueNameForEnv(ServiceBusConfig.SecurityRefreshQueueName),
durable: false,
exclusive: false,
autoDelete: false,
arguments: null);

return true;
}
catch (Exception ex)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ public class RabbitInboundQueueProvider
public Func<AuditEvent, Task> AuditEventQueueReceived;
public Func<UnitLocationEvent, Task> UnitLocationEventQueueReceived;
public Func<PersonnelLocationEvent, Task> PersonnelLocationEventQueueReceived;
public Func<SecurityRefreshEvent, Task> SecurityRefreshEventQueueReceived;

public RabbitInboundQueueProvider()
{
Expand Down Expand Up @@ -447,7 +448,6 @@ private async Task StartMonitoring()
}
catch (Exception ex)
{
//_channel.BasicNack(ea.DeliveryTag, false, false);
Logging.LogException(ex, Encoding.UTF8.GetString(ea.Body.ToArray()));
}

Expand All @@ -458,15 +458,12 @@ private async Task StartMonitoring()
if (UnitLocationEventQueueReceived != null)
{
await UnitLocationEventQueueReceived.Invoke(unitLocation);
//_channel.BasicAck(ea.DeliveryTag, false);
}
}
}
catch (Exception ex)
{
// Discard unit location events.
Logging.LogException(ex);
//_channel.BasicNack(ea.DeliveryTag, false, true);
}
}
};
Expand All @@ -477,7 +474,7 @@ private async Task StartMonitoring()
consumer: unitLocationQueueReceivedConsumer);
}

if (UnitLocationEventQueueReceived != null)
if (PersonnelLocationEventQueueReceived != null)
{
var personnelLocationQueueReceivedConsumer = new EventingBasicConsumer(_channel);
personnelLocationQueueReceivedConsumer.Received += async (model, ea) =>
Expand All @@ -493,26 +490,22 @@ private async Task StartMonitoring()
}
catch (Exception ex)
{
//_channel.BasicNack(ea.DeliveryTag, false, false);
Logging.LogException(ex, Encoding.UTF8.GetString(ea.Body.ToArray()));
}

try
{
if (personnelLocation != null)
{
if (UnitLocationEventQueueReceived != null)
if (PersonnelLocationEventQueueReceived != null)
{
await PersonnelLocationEventQueueReceived.Invoke(personnelLocation);
//_channel.BasicAck(ea.DeliveryTag, false);
}
}
}
catch (Exception ex)
{
// Discard unit location events.
Logging.LogException(ex);
//_channel.BasicNack(ea.DeliveryTag, false, true);
}
}
};
Expand All @@ -522,6 +515,48 @@ private async Task StartMonitoring()
autoAck: true,
consumer: personnelLocationQueueReceivedConsumer);
}

if (SecurityRefreshEventQueueReceived != null)
{
var securityRefreshEventQueueReceivedConsumer = new EventingBasicConsumer(_channel);
securityRefreshEventQueueReceivedConsumer.Received += async (model, ea) =>
{
if (ea != null && ea.Body.Length > 0)
{
SecurityRefreshEvent securityRefresh = null;
try
{
var body = ea.Body;
var message = Encoding.UTF8.GetString(body.ToArray());
securityRefresh = ObjectSerialization.Deserialize<SecurityRefreshEvent>(message);
}
catch (Exception ex)
{
Logging.LogException(ex, Encoding.UTF8.GetString(ea.Body.ToArray()));
}

try
{
if (securityRefresh != null)
{
if (SecurityRefreshEventQueueReceived != null)
{
await SecurityRefreshEventQueueReceived.Invoke(securityRefresh);
}
}
}
catch (Exception ex)
{
Logging.LogException(ex);
}
}
};

String securityRefreshEventQueueReceivedConsumerTag = _channel.BasicConsume(
queue: RabbitConnection.SetQueueNameForEnv(ServiceBusConfig.SecurityRefreshQueueName),
autoAck: true,
consumer: securityRefreshEventQueueReceivedConsumer);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,13 @@ public bool EnqueuePersonnelLocationEvent(PersonnelLocationEvent personnelLocati
return SendMessage(ServiceBusConfig.PersonnelLoactionQueueName, serializedObject, false, "300000");
}

public bool EnqueueSecurityRefreshEvent(SecurityRefreshEvent securityRefreshEvent)
{
var serializedObject = ObjectSerialization.Serialize(securityRefreshEvent);

return SendMessage(ServiceBusConfig.SecurityRefreshQueueName, serializedObject, false, "300000");
}

public bool VerifyAndCreateClients()
{
return RabbitConnection.VerifyAndCreateClients();
Expand Down
Loading

0 comments on commit d3e383b

Please sign in to comment.