@@ -2,8 +2,11 @@ package replication
22
33import (
44 "context"
5+ "fmt"
6+ "runtime/debug"
57 "time"
68
9+ "github.com/davecgh/go-spew/spew"
710 "github.com/formancehq/go-libs/v3/bun/bunpaginate"
811 "github.com/formancehq/go-libs/v3/collectionutils"
912 "github.com/formancehq/go-libs/v3/logging"
@@ -64,17 +67,31 @@ type PipelineHandler struct {
6467}
6568
6669func (p * PipelineHandler ) Run (ctx context.Context , ingestedLogs chan uint64 ) {
70+ p .logger .Debugf ("Pipeline started." )
6771 nextInterval := time .Duration (0 )
72+
73+ defer func () {
74+ fmt .Println ("Terminated." )
75+ if e := recover (); e != nil {
76+ fmt .Printf ("error: %s\r \n " , e )
77+ debug .PrintStack ()
78+ }
79+ }()
80+
6881 for {
6982 select {
7083 case ch := <- p .stopChannel :
84+ p .logger .Debugf ("Pipeline terminated." )
7185 close (ch )
7286 return
7387 case <- time .After (nextInterval ):
88+ p .logger .Debugf ("Fetch next batch." )
89+ spew .Dump (p .pipeline )
7490 var builder query.Builder
7591 if p .pipeline .LastLogID != nil {
7692 builder = query .Gt ("id" , * p .pipeline .LastLogID )
7793 }
94+ spew .Dump (builder )
7895 logs , err := p .store .ListLogs (ctx , common.InitialPaginatedQuery [any ]{
7996 PageSize : p .pipelineConfig .LogsPageSize ,
8097 Column : "id" ,
@@ -93,18 +110,21 @@ func (p *PipelineHandler) Run(ctx context.Context, ingestedLogs chan uint64) {
93110 }
94111 }
95112
113+ p .logger .Debugf ("Got %d items" , len (logs .Data ))
96114 if len (logs .Data ) == 0 {
97115 nextInterval = p .pipelineConfig .PullInterval
98116 continue
99117 }
100118
101119 for {
120+ p .logger .Debugf ("send to exporter" )
102121 _ , err := p .exporter .Accept (ctx , collectionutils .Map (logs .Data , func (log ledger.Log ) drivers.LogWithLedger {
103122 return drivers.LogWithLedger {
104123 Log : log ,
105124 Ledger : p .pipeline .Ledger ,
106125 }
107126 })... )
127+ p .logger .Debugf ("exported: %s" , err )
108128 if err != nil {
109129 p .logger .Errorf ("Error pushing data on exporter: %s, waiting for: %s" , err , p .pipelineConfig .PushRetryPeriod )
110130 select {
@@ -118,6 +138,7 @@ func (p *PipelineHandler) Run(ctx context.Context, ingestedLogs chan uint64) {
118138 }
119139
120140 lastLogID := logs .Data [len (logs .Data )- 1 ].ID
141+ p .logger .Debugf ("Move last log id to %d" , lastLogID )
121142 p .pipeline .LastLogID = lastLogID
122143
123144 select {
0 commit comments