Right way to start a background task per request in Quarkus

Viewed 1149

I wonder what is the good practice in Quarkus to run background task per request.

Something like this:

    @POST()
    @Path("v1")
    public Uni<Response> buildSomething() {
        // start a thread to build things in the background
        // when completed, save the id in DB

        // return immediately
        return Uni.createFrom().item(Response.accepted().build());
    }

    @GET()
    @Path("v1")
    public Uni<List<Long>> getSomethingThatHasBeenBuilt() {
        // fetch ids from DB
        return fetchIdsFromDB();
    }

I hope I can do something like a Go routine, for which I can set a timeout and log the error. I suspect one can probably inject a vertx instance and do the task in a worker thread pool, but I don't know how that can be implemented.

0 Answers
Related