com.github.tyrion9:mtask-proj

Parent pom providing dependency and plugin management for applications built with Maven

License

License

GroupId

GroupId

com.github.tyrion9
ArtifactId

ArtifactId

mtask-proj
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

pom
Description

Description

Parent pom providing dependency and plugin management for applications built with Maven
Project URL

Project URL

https://projects.spring.io/spring-boot/#/spring-boot-starter-parent/mtask-proj
Source Code Management

Source Code Management

https://github.com/tyrion9/mtask

Download mtask-proj

Filename Size
mtask-proj-0.0.1.pom 16 KB
Browse

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.tyrion9/mtask-proj/ -->
<dependency>
    <groupId>com.github.tyrion9</groupId>
    <artifactId>mtask-proj</artifactId>
    <version>0.0.1</version>
    <type>pom</type>
</dependency>
// https://jarcasting.com/artifacts/com.github.tyrion9/mtask-proj/
implementation 'com.github.tyrion9:mtask-proj:0.0.1'
// https://jarcasting.com/artifacts/com.github.tyrion9/mtask-proj/
implementation ("com.github.tyrion9:mtask-proj:0.0.1")
'com.github.tyrion9:mtask-proj:pom:0.0.1'
<dependency org="com.github.tyrion9" name="mtask-proj" rev="0.0.1">
  <artifact name="mtask-proj" type="pom" />
</dependency>
@Grapes(
@Grab(group='com.github.tyrion9', module='mtask-proj', version='0.0.1')
)
libraryDependencies += "com.github.tyrion9" % "mtask-proj" % "0.0.1"
[com.github.tyrion9/mtask-proj "0.0.1"]

Dependencies

compile (5)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-web jar 2.1.2.RELEASE
org.springframework.boot : spring-boot-starter-jetty jar 2.1.2.RELEASE
org.springframework.boot : spring-boot-starter-websocket jar 2.1.2.RELEASE
org.apache.commons : commons-lang3 jar 3.8.1
org.yaml : snakeyaml jar 1.23

provided (1)

Group / Artifact Type Version
org.projectlombok : lombok jar 1.18.4

test (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.1.2.RELEASE

Project Modules

  • mtask
  • mtask-spring-boot-autoconfigure
  • mtask-spring-boot-starter
  • mtask-sample

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

Versions

Version
0.0.1