Weever
Weever

Reputation: 25

How to terminate Quarkus Application after task finish

Our team use Quarkus framework, I need to create a project simply runs a task then exit itself.

I read the Quarkus document, and write the code in scala as below The EMRExecutionMonitor is call in Main Aplication Quarkus.run(classOf[EMRExecutionMonitor], args: _*)

Quarkus start up and I can see the logging but Quarkus would not exit even I called Quarkus.asyncExit(0) it just keeping running in console until I use Ctrl+C

I build project in Jar, and run as java -jar quarkus-run.jar

My expectation is when the logic finished in EMRExecutionMonitor, Quarkus application exit.

class EMRExecutionMonitor extends QuarkusApplication {

    private val logger = LoggerFactory.getLogger(this.getClass)
    override def run(args: String*): Int = {
        logger.info("start EMR execution monitoring job")
        Quarkus.waitForExit()
        Quarkus.asyncExit(0)
        0
    }
}

Thanks

Upvotes: 0

Views: 658

Answers (1)

PaMaly
PaMaly

Reputation: 11

I suggest you to use @QuarkusMain feature to execute your code within a main method. The following example executes & terminates your code at the end.

@QuarkusMain
public class EMRExecutor {

public static void main(String... args) {
    Quarkus.run(EMRExecutionMonitor.class, args);
    Quarkus.asyncExit(0);
}
public static class EMRExecutionMonitor implements QuarkusApplication{

    @Override
    public int run(String... args) throws Exception {
        Log.info("start EMR execution monitoring job");
        Quarkus.waitForExit();
        return 0;
    }
}
}

The console output will print out the termination info:

2023-11-19 13:51:45,671 INFO  [sk.mal.EMRExecutor$EMRExecutionMonitor] (Quarkus Main Thread) start EMR execution monitoring job
2023-11-19 13:51:45,717 INFO  [io.quarkus] (Quarkus Main Thread) quarkus-test stopped in 0.039s
Process finished with exit code 0

Upvotes: 0

Related Questions