0

I have a standard Command and Schedule Task items in Sitecore that is being executed based on interval. I am trying to track progress of this job in jobs.aspx or code but everytime code calls another api, Sitecore.Context.Job or whole Context is lost and Job in jobs.aspx is also finished immediately, even though process still runs and logs everything correctly. Code where context is lost:

[Service(typeof(MyService))]
    public class MyService
    {
    public async Task<HttpResponseMessage> GetResponse(string env)
            {
              // ...Deleted unnecessary part
    
                    using (var httpClient = new HttpClient())
                    {
                        var request = new HttpRequestMessage(HttpMethod.Post, url)
                        {
                            Content = new FormUrlEncodedContent(dict),
                        };
    
                        response = await httpClient.SendAsync(request).ConfigureAwait(false);
                    }//Context lost after SendAsync()
                }
                return response;
            }
    }

Is there a way to keep the job in Job Manager/Job Viewer or what would be the recommended approach here? Sitecore 10.0.1.

2
  • 5
    The whole point of an async request is to NOT block and wait for it to finish. Why don't you just send it off as a synchronous request instead if this is what you want?
    – Mark Cassidy
    Commented Dec 15, 2021 at 1:55
  • Yeah, that was the issue here. Making call synchronous kept sitecore job in job viewer till the end.
    – Kamil C
    Commented Dec 15, 2021 at 9:26

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.