Is there a way in Asp .Net Core to call my API recursively every 30 minutes?
The situation is the application and the app status payload is being passed at the same time. Some instances, the application is passed second, thus the app status does not have an application to reference making it a fail.
I have an ssms job that resets the status, but I need to retransfer them so I need to schedule call this function.
//[Obsolete("The appStat transfer is done real time. Used Internally only")]
[CustomRoute(Constants.api_transfer_app_status)]
[HttpPost]
public async Task<IActionResult> TransferAppStatusData()
{
MessageResponseModel response = await _arribaDBService.TransferAppStatusData2();
return new JsonResult(response);
}
2
Answers
Calling it recursively would be bad. I think you mean repeatedly/periodic.
Obviously you could do that in a rather hacky way by scheduling a task calling your API. Not great.
If you want to do things regardless of external calls, you can implement a
HostedService
(See Documentation)The link contains an example of how to do something on a timer. So you can call your method from C# code, even without having to call it over HTTP from the outside.
That said, you could move your ssms job into that service, too, so you can deploy it all together as single unit. It also means your service would not need to guess and hope it runs at the correct time. It would know the correct time to run, which is every time the status was reset.
You can achieve this with Hangfire, using Scheduled jobs it allows the use of CRON Expressions to specify the schedule i.e