Skip to content

Commit 5264491

Browse files
committed
cleanup the doc
1 parent 0fd28c6 commit 5264491

File tree

1 file changed

+12
-77
lines changed

1 file changed

+12
-77
lines changed

README.md

Lines changed: 12 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,13 @@ The README contains a shorter how to use.
3636

3737
- [JavaDoc](https://sterlp.github.io/spring-persistent-tasks/javadoc-core/org/sterl/spring/persistent_tasks/PersistentTaskService.html)
3838

39-
# Maven setup
39+
# Quickstart
4040

4141
- [Maven Central spring-persistent-tasks-core](https://central.sonatype.com/artifact/org.sterl.spring/spring-persistent-tasks-core/versions)
4242

43+
## Setup with Maven
44+
45+
4346
```xml
4447
<dependency>
4548
<groupId>org.sterl.spring</groupId>
@@ -48,69 +51,15 @@ The README contains a shorter how to use.
4851
</dependency>
4952
```
5053

51-
# Setup Spring
54+
## Setup Spring
5255

5356
```java
5457
@SpringBootApplication
5558
@EnableSpringPersistentTasks
5659
public class ExampleApplication {
5760
```
5861

59-
## Setup a spring persistent task
60-
61-
### As a class
62-
63-
```java
64-
@Component(BuildVehicleTask.NAME)
65-
@RequiredArgsConstructor
66-
@Slf4j
67-
public class BuildVehicleTask implements PersistentTask<Vehicle> {
68-
69-
private static final String NAME = "buildVehicleTask";
70-
public static final TaskId<Vehicle> ID = new TaskId<>(NAME);
71-
72-
private final VehicleRepository vehicleRepository;
73-
74-
@Override
75-
public void accept(Vehicle vehicle) {
76-
// do stuff
77-
// save
78-
vehicleRepository.save(vehicle);
79-
}
80-
// OPTIONAL
81-
@Override
82-
public RetryStrategy retryStrategy() {
83-
// run 5 times, multiply the execution count with 4, add the result in HOURS to now.
84-
return new MultiplicativeRetryStrategy(5, ChronoUnit.HOURS, 4)
85-
}
86-
// OPTIONAL
87-
// if the task in accept requires a DB transaction, join them together with the framework
88-
// if true the TransactionTemplate is used. Set here any timeouts.
89-
@Override
90-
public boolean isTransactional() {
91-
return true;
92-
}
93-
}
94-
```
95-
96-
Consider setting a timeout to the `TransactionTemplate`:
97-
98-
```java
99-
@Bean
100-
TransactionTemplate transactionTemplate(PlatformTransactionManager transactionManager) {
101-
TransactionTemplate template = new TransactionTemplate(transactionManager);
102-
template.setTimeout(10);
103-
return template;
104-
}
105-
```
106-
107-
### As a closure
108-
109-
Simple task will use defaults:
110-
111-
- Not a transactional task, e.g. HTTP calls
112-
- 4 executions, one regular and 3 retries, linear
113-
- using minutes with an offset of 1 which is added to now
62+
## Create a Task
11463

11564
```java
11665
@Bean
@@ -119,29 +68,15 @@ PersistentTask<Vehicle> task1(VehicleHttpConnector vehicleHttpConnector) {
11968
}
12069
```
12170

122-
### Task Transaction Management
123-
124-
[Transaction-Management Task](https://github.com/sterlp/spring-persistent-tasks/wiki/Transaction-Management)
125-
126-
## Queue a task execution
127-
128-
### Direct usage of the `TriggerService` or `PersistentTaskService`.
71+
## Trigger a task
12972

13073
```java
131-
private final TriggerService triggerService;
132-
private final PersistentTaskService persistentTaskService;
133-
134-
public void buildVehicle() {
135-
// Vehicle has to be Serializable
136-
final var v = new Vehicle();
137-
// set any data to v ...
138-
139-
// EITHER: queue it - will always run later
140-
triggerService.queue(BuildVehicleTask.ID.newUniqueTrigger(v));
74+
@Autowired
75+
PersistentTaskService persistentTaskService;
14176

142-
// OR: will queue it and run it now if possible.
143-
// if the scheduler service is missing it is same as using the TriggerService
144-
persistentTaskService.runOrQueue(BuildVehicleTask.ID.newUniqueTrigger(v));
77+
public void triggerTask1(Vehicle vehicle) {
78+
persistentTaskService.runOrQueue(
79+
TaskTriggerBuilder.newTrigger("task1").state(vehicle).build());
14580
}
14681
```
14782

0 commit comments

Comments
 (0)