1

Recently I tried to create a task with Dropwizard that would be triggered within a resource but I can't find a way to do it. I know that there are a integration with Quartz but that doesn't fit my needs (don't want to schedule tasks). Is the only option to make a POST to the task endpoint? If so, how can I do a request to /tasks/myTask ?

I don't want to change the architecture to something like producer/consumer, where I create a task in the resource and enqueue it to have then something executing the tasks enqueued.

Corgan
  • 669
  • 8
  • 11

2 Answers2

1

I posted a sample of how you can use a Managed service to execute tasks.

Running async jobs in dropwizard, and polling their status

Community
  • 1
  • 1
Nasir
  • 2,984
  • 30
  • 34
0

Is there a specific reason why you need to invoke the code as a task? I would extract the logic from the Task and put it in it's own class. Then you can use it from multiple places irrespective of the implementation. If it needs to be performed asynchronously, I've had success running Akka workers triggered from inside my Dropwizard services.

stve
  • 219
  • 2
  • 4
  • The code that I want to run is a long running task, so, I don't want the user to be waiting for the response. I was looking for a way to do it within the framework, but if there is no way... – Corgan Jan 04 '16 at 23:37
  • Another possible solution would be to create an ExecutorService as a Managed Object and make your long running code a Runnable that is executed in a separate thread asynchronously. – stve Jan 06 '16 at 17:56