Giter Club home page Giter Club logo

mtask's Introduction

Managed Task (MTask)

Background task is required for every enterprise projects.

Spring Framework support many kind of background tasks: Spring Scheduling, Spring Boot Quartz...

MTask is based on Spring Boot add new feature for monitoring and controlling on the fly.

  • Add/remove Scheduling Task via Rest API (Spring Scheduling theo fixedrate hoặc cron)
  • Stop/start scheduling task via API (Restful API)
  • Change parameter's tasks via API (Restful API)
  • Monitoring task by realtime log via Websocket

Step by step

More info in mtask-sample

1. Import maven library:

        <dependency>
            <groupId>com.github.tyrion9</groupId>
            <artifactId>mtask-spring-boot-starter</artifactId>
            <version>0.0.1</version>
        </dependency>

2. Write a class extends MTask

HelloWorldMTask

public class HelloWorldMTask extends MTask {
    private static final Logger log = LoggerFactory.getLogger(HelloWorldMTask.class);

    @Override
    public void run() {
        log.info("Hello World"); 

        mlog.log("Hello World");  // Websocket Log
    }
}

ComplexMTask: declare parameters, autowired bean to use

public class ComplexMTask extends MTask {
    private static final Logger log = LoggerFactory.getLogger(ComplexMTask.class);

    @Autowired
    private GreetingService greetingService;

    @MTaskParam("name")
    private String name;

    @Override
    public void run() {
        String greetingMsg = greetingService.greeting(name);

        log.info(greetingMsg);
        mlog.log(greetingMsg); // websocket log
    }
}

3. declare mtask configuration (yaml)

-   code: helloworld
    scheduled:
        period: 1000
    name: Hello World MTask
    className: sample.sample1.HelloWorldMTask
    autoStart: true
-   code: complex
    scheduled:
        period: 1000
    name: Autowired Param MTask
    className: sample.sample2.ComplexMTask
    params:
        name: HoaiPN
    autoStart: true

4. Run

@SpringBootApplication
@ComponentScan(basePackages = {"com.github.tyrion9.mtask", "sample"})
public class SampleApplication {
    public static void main(String[] args) {
        SpringApplication.run(SampleApplication.class, args);
    }
}

5. Monitor application

Client Tool is not developed yet, so use other tool for management:

  • Postman call rest API for management (stop/start/change parameters)
  • Simple Websocket Client - Chrome Plugin - to check log realtime

Real time log websocket-helloworld

websocket-complex

API list/stop/start/change parameters

curl -X GET http://localhost:8080/api

curl -X POST http://localhost:8080/api/helloworld/stop

curl -X POST http://localhost:8080/api/helloworld/start

rest-list

mtask's People

Contributors

tyrion9 avatar

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.