Skip to content

Commit b6e49b3

Browse files
committed
TD-5477: Create an email queue processing system.
1 parent b2cdaf8 commit b6e49b3

File tree

58 files changed

+719
-371
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+719
-371
lines changed

AdminUI/LearningHub.Nhs.AdminUI/LearningHub.Nhs.AdminUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
<PackageReference Include="HtmlSanitizer" Version="6.0.453" />
9090
<PackageReference Include="IdentityModel" Version="4.6.0" />
9191
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.2" />
92-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.48" />
92+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.49" />
9393
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
9494
<PackageReference Include="Microsoft.AspNetCore.Authentication.OpenIdConnect" Version="6.0.36" />
9595
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="6.0.36" />

LearningHub.Nhs.WebUI/LearningHub.Nhs.WebUI.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113
<PackageReference Include="HtmlAgilityPack" Version="1.11.72" />
114114
<PackageReference Include="IdentityModel" Version="4.6.0" />
115115
<PackageReference Include="LearningHub.Nhs.Caching" Version="2.0.0" />
116-
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.48" />
116+
<PackageReference Include="LearningHub.Nhs.Models" Version="3.0.49" />
117117
<PackageReference Include="linqtotwitter" Version="6.9.0" />
118118
<PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.19.0" />
119119
<PackageReference Include="Microsoft.ApplicationInsights.EventCounterCollector" Version="2.21.0" />

MessageQueueing/LearningHub.Nhs.MessageQueueing.Database/LearningHub.Nhs.MessageQueueing.Database.sqlproj

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,25 @@
5757
<ItemGroup>
5858
<Folder Include="Properties" />
5959
<Folder Include="Tables" />
60+
<Folder Include="Stored Procedures" />
61+
<Folder Include="Scripts" />
62+
<Folder Include="Scripts\Post-Deploy" />
63+
<Folder Include="Scripts\Post-Deploy\Scripts" />
64+
<Folder Include="User-Defined Table Types" />
65+
</ItemGroup>
66+
<ItemGroup>
67+
<Build Include="Tables\RequestType.sql" />
68+
<Build Include="Tables\RequestStatus.sql" />
69+
<Build Include="Tables\QueueRequests.sql" />
70+
<Build Include="Stored Procedures\CreateQueueRequests.sql" />
71+
<Build Include="Stored Procedures\GetQueueRequests.sql" />
72+
<Build Include="Stored Procedures\MessageDeliveryFailed.sql" />
73+
<Build Include="Stored Procedures\MessageDeliverySuccess.sql" />
74+
<Build Include="Stored Procedures\SaveFailedSingleEmail.sql" />
75+
<Build Include="User-Defined Table Types\QueueRequestTableType.sql" />
76+
</ItemGroup>
77+
<ItemGroup>
78+
<None Include="Scripts\Post-Deploy\Scripts\RequestStatusData.sql" />
79+
<None Include="Scripts\Post-Deploy\Scripts\RequestTypeData.sql" />
6080
</ItemGroup>
6181
</Project>
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT [dbo].[RequestStatus] ([Id], [RequestStatus]) VALUES (1, N'Pending')
2+
GO
3+
INSERT [dbo].[RequestStatus] ([Id], [RequestStatus]) VALUES (2, N'Sent')
4+
GO
5+
INSERT [dbo].[RequestStatus] ([Id], [RequestStatus]) VALUES (3, N'Failed')
6+
GO
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
INSERT [dbo].[RequestType] ([Id], [RequestType]) VALUES (1, N'Email')
2+
GO
3+
INSERT [dbo].[RequestType] ([Id], [RequestType]) VALUES (2, N'SMS')
4+
GO
5+
INSERT [dbo].[RequestType] ([Id], [RequestType]) VALUES (3, N'SingleEmail')
6+
GO
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Create PROCEDURE [dbo].[CreateQueueRequests]
2+
@QueueRequests dbo.QueueRequestTableType READONLY
3+
AS
4+
BEGIN
5+
6+
INSERT INTO QueueRequests (RequestTypeId, Recipient, TemplateId, Personalisation, Status, RetryCount, CreatedAt, DeliverAfter)
7+
SELECT 1, Recipient, TemplateId, Personalisation, 1, 0, SYSDATETIMEOFFSET(), DeliverAfter
8+
FROM @QueueRequests;
9+
END
10+
GO
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
CREATE PROCEDURE [dbo].[GetQueueRequests]
2+
AS
3+
BEGIN
4+
5+
select Id,Recipient,TemplateId,Personalisation,Status,RetryCount
6+
from dbo.QueueRequests
7+
where RequestTypeId = 1 and Status in (1,3) and RetryCount < 3 and (DeliverAfter is null or DeliverAfter <= SYSDATETIMEOFFSET())
8+
9+
END
10+
GO
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
CREATE PROCEDURE [dbo].[MessageDeliveryFailed]
2+
@Id int,
3+
@ErrorMessage nvarchar(max)
4+
AS
5+
BEGIN
6+
UPDATE [dbo].[QueueRequests]
7+
SET
8+
Status = 3,
9+
RetryCount = RetryCount + 1,
10+
ErrorMessage = @ErrorMessage,
11+
LastAttemptAt = SYSDATETIMEOFFSET()
12+
where Id = @Id;
13+
END
14+
GO
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
CREATE PROCEDURE [dbo].[MessageDeliverySuccess]
2+
@Id int,
3+
@NotificationId nvarchar(100)
4+
5+
AS
6+
BEGIN
7+
UPDATE [dbo].[QueueRequests]
8+
SET
9+
Status = 2,
10+
NotificationId = @NotificationId,
11+
RetryCount = RetryCount + 1,
12+
SentAt = SYSDATETIMEOFFSET(),
13+
LastAttemptAt = SYSDATETIMEOFFSET()
14+
where Id = @Id;
15+
END
16+
GO
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CREATE PROCEDURE [dbo].[SaveFailedSingleEmail]
2+
@Recipient nvarchar(255),
3+
@TemplateId nvarchar(50),
4+
@Personalisation nvarchar(max),
5+
@ErrorMessage nvarchar(max)
6+
AS
7+
BEGIN
8+
insert into [dbo].[QueueRequests] (RequestTypeId, Recipient, TemplateId, Personalisation, Status, CreatedAt, LastAttemptAt,ErrorMessage )
9+
values (3, @Recipient, @TemplateId, @Personalisation, 3, SYSDATETIMEOFFSET(), SYSDATETIMEOFFSET(), @ErrorMessage);
10+
END
11+
GO

0 commit comments

Comments
 (0)