1

I need to create a service which will handle long executing jobs. Currently I am trying to develop WebAPI REST service with, for example, endpoint "POST /api/start", which will return JobId. After that I will be polling service using some other endpoint like "GET /api/status/{jobId}".

The issue is that REST service cannot have state or at least it is not good practice. Maybe you could suggest me some of the good ways of separating service from an actual JobHandler? Or, if it is okay to do this in WebAPI, explain how to create singletone, which will not be disposed until IIS is reset.

Thank you.

UPDATE: After all investigation I decided to create WebAPI REST Service to communicate with client and for long executing jobs I developed WindowsService with WCF communication layer. It is the best solution I could find and it suits me very well. Thanks everybody.

  • 1
    I must admit that this isn't an area I have a ton of experience in (I'd be interested to hear the answer to this too, actually) but would it be OK for the service to kick off an executable on the server to do the job (or is that not what you had in mind)? – EJoshuaS - Stand with Ukraine Mar 26 '17 at 00:26
  • @EJoshuaS I had in mind executing operation right in memory, since I want to control its progress and I'm not sure it is possible with kicking off the exe. Or am I wrong? – Ilya Livshits Mar 26 '17 at 11:36
  • Depends on what you mean by "control." You could pass parameters to it at startup and/or use a message queue or database to pass it information at runtime. – EJoshuaS - Stand with Ukraine Mar 26 '17 at 15:18

1 Answers1

1

This may be helpful.

If you want to stick with polling, you should create a new REST resource, which contains the actual state and the progress of the long running task.

  • Thank you very much, but the issue I'm thinking about is how to make WebAPI service stateful properly, cause as far as I know, it will be stopped after last request in 20 mins (default) and all jobs will be deleted. How to avoid this? – Ilya Livshits Mar 25 '17 at 23:46
  • Use application wich runs outside IIS context. Good answer is [here] https://stackoverflow.com/questions/17726002/how-can-long-running-thread-work-inside-web-application – Anton Khramov Mar 26 '17 at 19:40