Hi,
I have a hangfire app running. Hangfire is responsible to start multiple different api services via recurring jobs:
[HttpPost]
public void Post([FromForm] Model value)
{
var apiUrl = value.ApiUrl; // for example http://api1.com
var interval = value.Interval;
RecurringJob.AddOrUpdate(value.ApiName, () => RunInBackground(apiUrl), Cron.MinuteInterval(value.Interval));
}
[DisableConcurrentExecutionWithParametersAttribute(timeoutInSeconds: 10 * 60)]
[AutomaticRetry(Attempts = 0)]
public async Task RunInBackground(string Url)
{
using (HttpClient httpClient = new HttpClient())
{
var response = await httpClient.GetAsync(Url);
httpClient.DefaultRequestHeaders.Accept.Clear();
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(“application/json”));
var responseFromApi = await response.Content.ReadAsStringAsync();
if(responseFromApi != null)
return true;
}
}
The thing I want to accomplish Is to wait for the responses from the api:s, before starting the job again. How can I do that?
So basically I want this:
Start a job with a parameter to the API
The job sends a request to the API
Wait for response (because the APIs can be working with aalot of data that takes time)
Start the job again when I get a response from the api
Anyone who can help me?