Skip to content

Commit

Permalink
Call WaitForNewRows at the end of each QRepWorkflow (#561)
Browse files Browse the repository at this point in the history
  • Loading branch information
heavycrystal authored Oct 23, 2023
1 parent 909bbb1 commit da12a21
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
3 changes: 3 additions & 0 deletions flow/activities/flowable.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,9 @@ func (a *FlowableActivity) QRepWaitUntilNewRows(ctx context.Context,
defer connectors.CloseConnector(srcConn)
pgSrcConn := srcConn.(*connpostgres.PostgresConnector)

log.WithFields(log.Fields{
"flowName": config.FlowJobName,
}).Infof("current last partition value is %v\n", last)
attemptCount := 1
for {
activity.RecordHeartbeat(ctx, fmt.Sprintf("no new rows yet, attempt #%d", attemptCount))
Expand Down
25 changes: 18 additions & 7 deletions flow/workflows/qrep_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,22 @@ func (q *QRepFlowExecution) consolidatePartitions(ctx workflow.Context) error {
return nil
}

func (q *QRepFlowExecution) waitForNewRows(ctx workflow.Context, lastPartition *protos.QRepPartition) error {
q.logger.Info("idling until new rows are detected")

ctx = workflow.WithActivityOptions(ctx, workflow.ActivityOptions{
StartToCloseTimeout: 16 * 365 * 24 * time.Hour, // 16 years
HeartbeatTimeout: 5 * time.Minute,
})

if err := workflow.ExecuteActivity(ctx, flowable.QRepWaitUntilNewRows, q.config,
lastPartition).Get(ctx, nil); err != nil {
return fmt.Errorf("failed while idling for new rows: %w", err)
}

return nil
}

func QRepFlowWorkflow(
ctx workflow.Context,
config *protos.QRepConfig,
Expand All @@ -257,11 +273,6 @@ func QRepFlowWorkflow(
maxParallelWorkers = int(config.MaxParallelWorkers)
}

waitBetweenBatches := 5 * time.Second
if config.WaitBetweenBatchesSeconds > 0 {
waitBetweenBatches = time.Duration(config.WaitBetweenBatchesSeconds) * time.Second
}

// register a signal handler to terminate the workflow
terminateWorkflow := false
signalChan := workflow.GetSignalChannel(ctx, shared.CDCFlowSignalName)
Expand Down Expand Up @@ -345,9 +356,9 @@ func QRepFlowWorkflow(
}

// sleep for a while and continue the workflow
err = workflow.Sleep(ctx, waitBetweenBatches)
err = q.waitForNewRows(ctx, lastPartition)
if err != nil {
return fmt.Errorf("failed to sleep: %w", err)
return err
}

workflow.GetLogger(ctx).Info("Continuing as new workflow",
Expand Down

0 comments on commit da12a21

Please sign in to comment.