Add delay to start message consumption until 8:10 AM and implement time calculation
This commit is contained in:
parent
79e0fe7f1b
commit
0ab75b2a19
2 changed files with 28 additions and 1 deletions
|
|
@ -13,6 +13,9 @@ var configuration = new ConfigurationBuilder()
|
||||||
|
|
||||||
WriteToConsole("Consumer Start!");
|
WriteToConsole("Consumer Start!");
|
||||||
|
|
||||||
|
// Wait until 8:00 AM before starting to consume messages
|
||||||
|
await WaitUntil8AM();
|
||||||
|
|
||||||
var host = configuration["Rabbit:Host"] ?? "";
|
var host = configuration["Rabbit:Host"] ?? "";
|
||||||
var user = configuration["Rabbit:User"] ?? "";
|
var user = configuration["Rabbit:User"] ?? "";
|
||||||
var pass = configuration["Rabbit:Password"] ?? "";
|
var pass = configuration["Rabbit:Password"] ?? "";
|
||||||
|
|
@ -95,6 +98,30 @@ async Task CallRestApi(string requestData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async Task WaitUntil8AM()
|
||||||
|
{
|
||||||
|
// Get current time in Bangkok timezone
|
||||||
|
var bangkokTimeZone = TimeZoneInfo.FindSystemTimeZoneById("SE Asia Standard Time");
|
||||||
|
var currentTime = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, bangkokTimeZone);
|
||||||
|
|
||||||
|
var targetTime = new DateTime(currentTime.Year, currentTime.Month, currentTime.Day, 8, 10, 0);
|
||||||
|
|
||||||
|
// If current time is already past 8:10 AM today, start immediately
|
||||||
|
if (currentTime >= targetTime)
|
||||||
|
{
|
||||||
|
WriteToConsole($"Current time is {currentTime:HH:mm:ss}. Starting consumer immediately.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate time to wait
|
||||||
|
var timeToWait = targetTime - currentTime;
|
||||||
|
WriteToConsole($"Current time is {currentTime:HH:mm:ss}. Waiting until 08:10:00 to start consuming messages.");
|
||||||
|
WriteToConsole($"Time to wait: {timeToWait.Hours} hours, {timeToWait.Minutes} minutes, {timeToWait.Seconds} seconds");
|
||||||
|
|
||||||
|
await Task.Delay(timeToWait);
|
||||||
|
WriteToConsole("It's now 08:10:00. Starting to consume messages from queue.");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public class ResponseObject
|
public class ResponseObject
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ export default function () {
|
||||||
//"https://bma-hrms.bangkok.go.th/api/v1/leave/fake-check-in",
|
//"https://bma-hrms.bangkok.go.th/api/v1/leave/fake-check-in",
|
||||||
//"https://hrmsbkk.case-collection.com/api/v1/org/dotnet/keycloak/439fa36d-6bc5-4ef5-95aa-ef29e64d2e9f",
|
//"https://hrmsbkk.case-collection.com/api/v1/org/dotnet/keycloak/439fa36d-6bc5-4ef5-95aa-ef29e64d2e9f",
|
||||||
"https://hrms.bangkok.go.th/api/v1/org/dotnet/keycloak/bafc5795-befc-4d3f-a461-3533c38a5fc1",
|
"https://hrms.bangkok.go.th/api/v1/org/dotnet/keycloak/bafc5795-befc-4d3f-a461-3533c38a5fc1",
|
||||||
{ headers: headers }
|
{ headers: headers },
|
||||||
);
|
);
|
||||||
|
|
||||||
// ตรวจสอบการตอบสนอง
|
// ตรวจสอบการตอบสนอง
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue