
Spring Persistent Tasks
A simple task management framework designed to queue and execute asynchronous tasks with support for database persistence and a user-friendly interface. It can be used to implement scheduling patterns or outbound patterns.
Focus is the usage with spring boot and JPA and AI.
Secondary goal is to support Poor mans Workflow
AI setup
use the available skill in skills
Spring compatibility
- use 2.4.x for Spring 3
- use 4.x.x for Spring 4
Spring 3 braqnch
Key Features ✨
- JPA-Powered Persistence - Automatically persists tasks to your database
- Spring Boot Auto-Configuration - Simple setup with @EnableSpringPersistentTasks
- Clustering Support for tasks - Built-in lock management for distributed environments and tasks
- Clustering Support for cron tasks - Support for cron tasks in a cluster - run on just one node
- Type-Safe Tasks - Generic task definitions with state objects
- Retry Mechanisms - Automatic retry policies for failed executions
- Transactional Integration - Works with Spring’s transaction management
- Queue Management - Intelligent task queuing and prioritization
- Different DB Supports - MySQL, azure-sql-edge, PostgreSQL, and H2
Documentation
Use the doc for more advanced examples.
The README contains a shorter how to use.
Known issues
- spring-boot-devtools: cause java.lang.ClassCastException exceptions during the state serialization - this is a java/spring issue
Known limitations
DBMS have missing bad row lock implementation
The framework briefly locks a row or trigger to ensure that each trigger is started only on a single node when a cluster is in use. However, some databases still do not support proper row locking and instead lock the entire table. This is not a critical issue but can slow down task selection in very large clusters.
- mySQL
- Azure SQL Edge (maybe also MSSQL)
DBs for storage
Tested in the pipeline

Supported in theory
- MSSQL, as azure-sql-edge is tested
Not supported
- mySQL: sequences are not supported
JavaDoc
Quickstart
Setup with Maven
Consider using the AI skill – if you improve it please create a PR.
<dependency>
<groupId>org.sterl.spring</groupId>
<artifactId>spring-persistent-tasks-core</artifactId>
<version>4.x.x</version>
</dependency>
Setup Spring
@SpringBootApplication
@EnableSpringPersistentTasks
public class ExampleApplication {
Create a Task
@Bean
PersistentTask<Vehicle> task1(VehicleHttpConnector vehicleHttpConnector) {
return v -> vehicleHttpConnector.send(v);
}
Trigger a task
@Autowired
PersistentTaskService persistentTaskService;
public void triggerTask1(Vehicle vehicle) {
persistentTaskService.runOrQueue(
TriggerBuilder.newTrigger("task1").state(vehicle).build());
}
JUnit Tests
Setup DB with Liquibase
Liquibase is supported. Either import all or just the required versions.
Maven
Option 1: Just include the master file
<include file="spring-persistent-tasks/db.changelog-master.xml" />
Option 2: import changesets on by one
<include file="spring-persistent-tasks/db/pt-changelog-v1.xml" />
Setup UI
Maven
<dependency>
<groupId>org.sterl.spring</groupId>
<artifactId>spring-persistent-tasks-ui</artifactId>
<version>x.x.x</version>
</dependency>
Setup Spring
@SpringBootApplication
@EnableSpringPersistentTasks
@EnableSpringPersistentTasksUI
public class ExampleApplication {
Open the UI
Schedulers

Triggers

History

Alternatives
- quartz
- db-scheduler
- jobrunr
评论