From 6b06d265ea69621e2b2a2513be2181527c30ba9b Mon Sep 17 00:00:00 2001
From: plockwood <paul.lockwood@education.gov.uk>
Date: Wed, 6 Nov 2024 11:56:58 +0000
Subject: [PATCH] Change to a start delay

---
 .../Services/CreateCompleteProjectsService.cs              | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Dfe.Academies.Academisation.WebApi/Services/CreateCompleteProjectsService.cs b/Dfe.Academies.Academisation.WebApi/Services/CreateCompleteProjectsService.cs
index 11f777fe5..abeef3b85 100644
--- a/Dfe.Academies.Academisation.WebApi/Services/CreateCompleteProjectsService.cs
+++ b/Dfe.Academies.Academisation.WebApi/Services/CreateCompleteProjectsService.cs
@@ -16,11 +16,16 @@ public CreateCompleteProjectsService(ILogger<CreateCompleteProjectsService> logg
 		{
 			_logger = logger;
 			_factory = factory;
-			_delayInMilliseconds = GetSecureRandomDelay(1000, 30000) + config.GetValue<int?>("SendProjectsToCompletePollingDelay") ?? 60_000;
+			_delayInMilliseconds = config.GetValue<int?>("SendProjectsToCompletePollingDelay") ?? 60_000;
 		}
 
 		protected override async Task ExecuteAsync(CancellationToken stoppingToken)
 		{
+			// delay start to prevent runtime colisions 
+			var startDelayInMilliseconds = GetSecureRandomDelay(1000, 60000);
+
+			await Task.Delay(startDelayInMilliseconds, stoppingToken);
+
 			while (!stoppingToken.IsCancellationRequested)
 			{
 				using (var scope = _factory.CreateScope())