-
Notifications
You must be signed in to change notification settings - Fork 16
/
step_handler.go
56 lines (47 loc) · 2.12 KB
/
step_handler.go
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
package gobatch
// Task is a function type for doing work in a simple step
type Task func(execution *StepExecution) BatchError
// Handler is a interface for doing work in a simple step
type Handler interface {
//Handle implement handler logic here
Handle(execution *StepExecution) BatchError
}
// Reader is for loading data in a chunk step
type Reader interface {
//Read each call of Read() will return a data item, if there is no more data, a nil item will be returned.
//If there is an error, nil item and a BatchError will return
Read(chunkCtx *ChunkContext) (interface{}, BatchError)
}
// Processor is for processing data in a chunk step
type Processor interface {
//Process process an item from reader and return a result item
Process(item interface{}, chunkCtx *ChunkContext) (interface{}, BatchError)
}
// Writer is for writing data in a chunk step
type Writer interface {
//Write write items generated by processor in a chunk
Write(items []interface{}, chunkCtx *ChunkContext) BatchError
}
// OpenCloser is used doing initialization and cleanups for Reader or Writer
type OpenCloser interface {
//Open do initialization for Reader or Writer
Open(execution *StepExecution) BatchError
//Close do cleanups for Reader or Writer
Close(execution *StepExecution) BatchError
}
// Partitioner split an execution of step into multiple sub executions.
type Partitioner interface {
//Partition generate sub step executions from specified step execution and partitions count
Partition(execution *StepExecution, partitions uint) ([]*StepExecution, BatchError)
//GetPartitionNames generate sub step names from specified step execution and partitions count
GetPartitionNames(execution *StepExecution, partitions uint) []string
}
// PartitionerFactory can create Partitioners, it is used by Reader usually.
type PartitionerFactory interface {
GetPartitioner(minPartitionSize, maxPartitionSize uint) Partitioner
}
// Aggregator merge results of sub step executions of a chunk step
type Aggregator interface {
//Aggregate aggregate result from all sub step executions
Aggregate(execution *StepExecution, subExecutions []*StepExecution) BatchError
}