Ted scheduler


License

License

GroupId

GroupId

com.github.labai
ArtifactId

ArtifactId

ted-scheduler
Last Version

Last Version

0.3.4
Release Date

Release Date

Type

Type

jar
Description

Description

Ted scheduler
Ted scheduler
Project URL

Project URL

https://github.com/labai/ted
Source Code Management

Source Code Management

https://github.com/labai/ted

Download ted-scheduler

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.labai/ted-scheduler/ -->
<dependency>
    <groupId>com.github.labai</groupId>
    <artifactId>ted-scheduler</artifactId>
    <version>0.3.4</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.labai/ted-scheduler/
implementation 'com.github.labai:ted-scheduler:0.3.4'
// https://jarcasting.com/artifacts/com.github.labai/ted-scheduler/
implementation ("com.github.labai:ted-scheduler:0.3.4")
'com.github.labai:ted-scheduler:jar:0.3.4'
<dependency org="com.github.labai" name="ted-scheduler" rev="0.3.4">
  <artifact name="ted-scheduler" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.labai', module='ted-scheduler', version='0.3.4')
)
libraryDependencies += "com.github.labai" % "ted-scheduler" % "0.3.4"
[com.github.labai/ted-scheduler "0.3.4"]

Dependencies

compile (3)

Group / Artifact Type Version
com.github.labai : ted-driver jar 0.3.4
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.3.60
org.slf4j : slf4j-api jar 1.7.12

provided (2)

Group / Artifact Type Version
org.postgresql : postgresql jar 42.0.0.jre7
com.oracle.database.jdbc : ojdbc6 jar 11.2.0.4

test (7)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar 5.4.1
org.apache.commons : commons-lang3 jar 3.3.2
com.zaxxer : HikariCP jar 3.3.0
ch.qos.logback : logback-classic jar 1.1.7
com.google.code.gson : gson jar 2.8.0
org.jetbrains.kotlin : kotlin-test-junit jar 1.3.60
org.awaitility : awaitility jar 3.1.6

Project Modules

There are no modules declared in this project.

TED - Task Execution Driver

About

TED is library for Java to handle task execution.

Tasks are stored in Oracle/Postgres/MySql db (table tedtask). TED checks for new tasks in that table, retrieves them, calls task processor and after finish sets status (DONE, ERROR or RETRY).

Main things kept in mind while creating TED
  • simplicity of use;
  • good performance;
  • no jar dependencies;
  • easy support - it is easy to view task history in db using any sql browser, restart task;
  • can be used for short (milliseconds) and long (hours) tasks;
Features

Main features:

  • is a part of war (or other app), no needs for separate process;
  • tasks are in db, thus tasks remain after restart of app, it is easy to browse history ann manage using standard sql;
  • there are auto cleaning after 35 days;
  • task will be executed only by one application instance;
  • works with PostgreSQL (9.5+), Oracle DB or MySql (8+); from Java 1.8;
  • task configuration is in separate ted.properties file, may be tuned without recompile;
  • it is possible to retry task by it's own retry policy;
  • channels - allows to assign separate thread pools to different types of tasks;
  • ted-scheduler allows to use ted-driver as scheduler engine
  • ted-spring-support easily integrates into spring

See Ted features in wiki.

TED can be helpful when:

  • you need to have task history in db table, easy browse, restart one or few tasks;
  • to be sure task will remain even if app shutdowns before task finish;
  • need to balance load between few instances (e.g. tomcats);
  • need retry logic;

Usage example

Using ted-spring-support

<dependency>
   <groupId>com.github.labai</groupId>
   <artifactId>ted-spring-support</artifactId>
   <version>0.3.2</version>
</dependency>
@EnableTedTask
@Configuration
public class TedConfig {
}
@Service   
public class Tasks {

    @TedTaskProcessor(name = "TASK1")
    public TedResult task1(TedTask task) {
        logger.info("start TASK1: {}", task.getData());
        return TedResult.done();
    }
    
    // scheduler task
    @TedSchedulerProcessor(name = "SCH_1", cron = "1 * * * * *")
    public String schedulerTask1() {
        logger.info("Start schedulerTask1");
        return "ok";
    }
}

and then create tasks

@Service   
public class MyService {
    @Autowired
    private TedTaskFactory tedTaskFactory;
    
    private void createTasks() {
        tedTaskFactory.createTask("TASK1", "(task parameters...)");
    }
}

See also Start-to-use and Start-to-use-in-spring in wiki. More samples can be found in ted-samples.

DB Structure

tedtask table

All tasks are stored into tedtask table. TED driver periodically checks for new tasks. tedtask table is important part of TED. As structure is simple and open, a standard sql or some own tools can be used to browse, monitor and manage tasks. tedtask structure:

  • taskid - Id - primary key
  • system - System id. E.g. myapp, or myapp.me for dev
  • name - Task name
  • status - Status
  • channel - Channel
  • nextts - Postponed execute (next retry) timestamp
  • batchid - Reference to batch taskId
  • key1 - Search key 1 (task specific)
  • key2 - Search key 2 (task specific)
  • data - Task data (parameters)
  • msg - Status message
  • createts - Record create timestamp
  • startts - Execution start timestamp
  • finishts - Execution finish timestamp
  • retries - Retry count
  • bno - Internal TED field (batch number)

Task parameters can be serialized into string (e.g. to json), and stored into data column.

Statuses

  • NEW – new
  • WORK – taken for process
  • RETRY – retryable error while executing, will retry later
  • DONE – finished successfully
  • ERROR – error occurred, will not retry

Versions

Version
0.3.4