-
Notifications
You must be signed in to change notification settings - Fork 0
/
iteration.go
57 lines (53 loc) · 2.06 KB
/
iteration.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
57
package gobulk
import (
"time"
"go.uber.org/zap"
)
// Iteration is the task to import a format from the first to the last container
type Iteration struct {
// ID should be used as identifier of the iteration in tracker
ID uint64
// Number should be used to identify the iteration (re-importing a format should result in increasing the number)
Number uint
// Format referrs to the format the iteration is about
Format Format
// When the iteration / import task has been created. This can be used to track how long a "full" import took
Created time.Time
// When the iteration / import task has been changed the last time. This can be used to find out how long the iteration took
Modified *time.Time
// The last container that has been tracked. This should be used by the listener to not start from scratch on every execution
LastTrackedContainer *Container
// The last container that has been sucessfully processed.
LastProcessedContainer *Container
// Input defines where to get the containers from e.g. objects from AWS S3 or files from a filesystem
Input Input
// Output defines where to store the data e.g. to Elasticsearch or a filesystem
Output Output
// Tracker is used to store the listening protocol and track errors
Tracker Tracker
}
// GetIteration returns a new or the format latest iteration based on the format NewIterationOnRestart
// configuration. The result iteration is preset with the format, tracker, input and output before
// being returned.
func GetIteration(format Format, tracker Tracker) (*Iteration, error) {
iteration, err := tracker.CurrentIteration(format)
if err != nil {
return nil, err
}
if format.NewIterationOnRestart() || iteration == nil {
var number uint = 1
if iteration != nil {
number = iteration.Number + 1
}
iteration, err = tracker.NewIteration(format, number)
if err != nil {
return nil, err
}
}
format.SetIteration(iteration)
format.Logger().Info("iteration has been set for the format",
zap.Int("iteration_number", int(iteration.Number)),
zap.Int("iteration_id", int(iteration.ID)),
)
return iteration, nil
}