/
TaskLifecycleListener.java
92 lines (82 loc) · 3.38 KB
/
TaskLifecycleListener.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package ru.yoomoney.tech.dbqueue.config;
import ru.yoomoney.tech.dbqueue.api.TaskExecutionResult;
import ru.yoomoney.tech.dbqueue.api.TaskRecord;
import ru.yoomoney.tech.dbqueue.settings.QueueLocation;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
/**
* Listener for task processing lifecycle.
*
* @author Oleg Kandaurov
* @since 09.07.2017
*/
public interface TaskLifecycleListener {
/**
* Event of task picking from the queue.
* <p>
* Triggered when there is a task in the queue, which is ready for processing.
* <p>
* Might be useful for monitoring problems with database performance.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param taskRecord Raw task data.
* @param pickTaskTime Time spent on picking the task from the queue in millis.
*/
void picked(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location, @Nonnull TaskRecord taskRecord,
long pickTaskTime);
/**
* The start event of task processing.
* <p>
* Always triggered when task was picked.
* <p>
* Might be useful for updating a logging context.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param taskRecord Raw task data.
*/
void started(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location, @Nonnull TaskRecord taskRecord);
/**
* Event for completion of client logic when task processing.
* <p>
* Always triggered when task processing has completed successfully.
* <p>
* Might be useful for monitoring successful execution of client logic.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param taskRecord Raw task data.
* @param executionResult Result of task processing.
* @param processTaskTime Time spent on task processing in millis, without the time for task picking from the queue.
*/
void executed(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location, @Nonnull TaskRecord taskRecord,
@Nonnull TaskExecutionResult executionResult, long processTaskTime);
/**
* Event for completion the task execution in the queue.
* <p>
* Always triggered when task was picked up for processing.
* Called even after {@link #crashed}.
* <p>
* Might be useful for recovery of initial logging context state.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param taskRecord Raw task data.
*/
void finished(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location, @Nonnull TaskRecord taskRecord);
/**
* Event for abnormal queue processing.
* <p>
* Triggered when unexpected error occurs during task processing.
* <p>
* Might be useful for tracking and monitoring errors in the system.
*
* @param shardId Shard identifier, which processes the queue.
* @param location Queue location.
* @param taskRecord Raw task data.
* @param exc An error caused the crash.
*/
void crashed(@Nonnull QueueShardId shardId, @Nonnull QueueLocation location, @Nonnull TaskRecord taskRecord,
@Nullable Exception exc);
}