GithubHelp home page GithubHelp logo

anthony-foulfoin / spring-task-launcher Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 1.0 58 KB

A simple example of how to execute and monitor an external batch or task contained in and external jar from a Spring Boot app

Java 100.00%

spring-task-launcher's Introduction

Spring Task-Launcher

An exemple of how to execute a batch (a "task") contained in an exernal jar from a Spring Boot app, in a sub-process. This example can be used to launch, monitor, cancel, and execute mutliple external jar in parallel.

The status of the batchs, the last succeeded execution date are persisted in the database (embeded h2), and can be retrieved by making Rest requests (Defined in TaskController)

Stack

  1. Java 8
  2. Spring Boot >= 2.x

How to use it

Basic launch

The example can be used as-it and provides a minimal working example. You just have to:

  • Modify the jar-path property in the application.yml file to set the path of the java jar you want to execute
  • Launch the app
    • ./gradlew bootRun on linux / MacOS
    • .\gradlew.bat bootRun on Windows
  • Launch the Task by calling this url : POST http://localhost:8080/v1/tasks/DEFAULT/launch
    • A simple java -jar is performed on the specified file. The current spring profile is set as param of the launched jar: -Dspring.profiles.active=...
  • That's all ! Now you can use the another endpoints to monitor the execution

Monitoring

You can:

  • Get the last successful execution date of a task, e.g. GET http://localhost:8080/v1/tasks/DEFAULT/last-exec
  • Get the status of a task (running or stopped), e.g. GET http://localhost:8080/v1/tasks/DEFAULT/status
  • Stop a running task, e.g. POST http://localhost:8080/v1/tasks/DEFAULT/cancel
  • A database lock is used to prevent launching the same task twice, by checking the running field.
    • You can unlock it by changing the runnning value in DB, e.g POST http://localhost:8080/v1/tasks/DEFAULT/in-progress/false

Tune it

This example is very basic and show how to launch and monitor a sigle task. You can use this code in your existing app and modify the TASK enum, and the controller to make it launching any batch you want

spring-task-launcher's People

Contributors

cbm-afoulfoin avatar

Watchers

 avatar

Forkers

shi-hailong

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.