// Worker waits for pending withdrawals and completes them
Worker waits for pending withdrawals and completes them
// Worker waits for pending withdrawals and completes them
func (w *WithdrawalHandler) Worker(ctx context.Context) error {
	onPendingWithdrawalCreated := w.pendingWithdrawalCreated.Subscribe(event.AtLeastOnceGuarantee)
	defer w.pendingWithdrawalCreated.Unsubscribe(onPendingWithdrawalCreated)
	t := time.NewTicker(5 * time.Minute)
	for {
		select {
		case <-onPendingWithdrawalCreated:
			err := w.CompleteAllPendingWithdrawals(ctx)
			if err != nil {
				return stacktrace.Propagate(err, "")
			}
		case <-t.C:
			err := w.CompleteAllPendingWithdrawals(ctx)
			if err != nil {
				return stacktrace.Propagate(err, "")
			}
			err = w.AutoWithdrawBalances(ctx)
			if err != nil {
				return stacktrace.Propagate(err, "")
			}
		case <-ctx.Done():
			return nil
		}
	}
}
func ( w * WithdrawalHandler ) Worker ( ctx context . Context ) error { onPendingWithdrawalCreated := w . pendingWithdrawalCreated . Subscribe ( event . AtLeastOnceGuarantee ) defer w . pendingWithdrawalCreated . Unsubscribe ( onPendingWithdrawalCreated ) t := time . NewTicker ( 5 * time . Minute ) for { select { case <- onPendingWithdrawalCreated : err := w . CompleteAllPendingWithdrawals ( ctx ) if err != nil { return stacktrace . Propagate ( err , " " ) } case <- t . C : err := w . CompleteAllPendingWithdrawals ( ctx ) if err != nil { return stacktrace . Propagate ( err , " " ) } err = w . AutoWithdrawBalances ( ctx ) if err != nil { return stacktrace . Propagate ( err , " " ) } case <- ctx . Done ( ) : return nil } } }
Worker waits for pending withdrawals and completes them
Worker waits for pending withdrawals and completes them