5

I have a simple DropWizard service and I'd like a REST API to start a long running processing task - both CPU and I/O bound. REST call will not wait for task completion, notification will happen by polling/long polling/web socket.

For now, I'd prefer if I can do this in Dropwizard and keep everything in single deployable JAR. What are my options?

UPDATE: I am interested in what my options are regarding running long running tasks in Dropwizard, deployed as single jar without external dependencies. Just spawn a new thread? Assuming there are just few such requests it would probably work but there should be better options.

bh213
  • 6,343
  • 9
  • 43
  • 52
  • stackoverflow is really for help with a specific problem, not helping you choose a design. That being said, consider WebHooks. – Joakim Erdfelt Sep 05 '14 at 17:11
  • @joakim-erdfelt - added more details to my original question, hopefully makes more sense now. – bh213 Sep 05 '14 at 19:48

1 Answers1

14

You probably want to use a managed resource:

https://dropwizard.io/en/stable/manual/core.html#managed-objects

to setup a thread pool. Then, your initial request could push a message onto a queue. Your thread pool can pull messages off the queue and process them asynchronously.

You could maybe provide an additional endpoint so that clients can obtain the current state of the asynchronous process.

senfo
  • 28,488
  • 15
  • 76
  • 106
Daniel Scott
  • 7,418
  • 5
  • 39
  • 58
  • Can you provide an example please? – me1111 Jan 06 '16 at 15:08
  • Are websockets are necessary for this case? – me1111 Jan 06 '16 at 16:22
  • It's a pretty big project to give an example, you need to write front- and back-end components and the back-end needs to handle multiple requests. Which part specifically? I'm sure there are plenty of examples if you search around. – Daniel Scott Jan 08 '16 at 11:15
  • Websockets aren't 'necessary' - but it depends on your UI. You could just reload part of the screen to update the status. – Daniel Scott Jan 08 '16 at 11:16
  • I am interested in back-end part only, could you please take a look at my question here http://stackoverflow.com/questions/34653177/running-async-jobs-in-dropwizard-and-polling-their-status/34670685 – me1111 Jan 08 '16 at 12:54
  • The answer in your linked question is exactly what I would have written. If you need more help, then I think you need to show how far you've got, and ask a more specific problem. – Daniel Scott Jan 09 '16 at 20:47
  • 2
    Link is broken. Update it to http://www.dropwizard.io/0.9.2/docs/manual/core.html#man-core-managed ? – Craig P. Motlin Jan 22 '16 at 14:36