Skip to content

Commit

Permalink
added timeout for long CDC pulls (#574)
Browse files Browse the repository at this point in the history
fixes #562
  • Loading branch information
heavycrystal authored Oct 25, 2023
1 parent 0a30091 commit deffa20
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
10 changes: 10 additions & 0 deletions flow/connectors/postgres/cdc.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,16 @@ func (p *PostgresCDCSource) consumeStream(

var standByLastLogged time.Time

shutdown := utils.HeartbeatRoutine(p.ctx, 10*time.Second, func() string {
jobName := req.FlowJobName
currRecords := len(records.Records)
return fmt.Sprintf("pulling records for job - %s, currently have %d records", jobName, currRecords)
})

defer func() {
shutdown <- true
}()

for {
if time.Now().After(nextStandbyMessageDeadline) ||
(len(records.Records) >= int(req.MaxBatchSize)) {
Expand Down
2 changes: 1 addition & 1 deletion flow/connectors/utils/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func HeartbeatRoutine(
go func() {
for {
msg := fmt.Sprintf("heartbeat #%d: %s", counter, message())
activity.RecordHeartbeat(ctx, msg)
RecordHeartbeatWithRecover(ctx, msg)
counter += 1
to := time.After(interval)
select {
Expand Down
4 changes: 1 addition & 3 deletions flow/workflows/sync_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,7 @@ func (s *SyncFlowExecution) executeSyncFlow(

startFlowCtx := workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
StartToCloseTimeout: 72 * time.Hour,
// TODO: activity needs to call heartbeat.
// see https://github.com/PeerDB-io/nexus/issues/216
HeartbeatTimeout: 24 * time.Hour,
HeartbeatTimeout: 5 * time.Minute,
})

// execute StartFlow on the peers to start the flow
Expand Down

0 comments on commit deffa20

Please sign in to comment.