summaryrefslogtreecommitdiff
path: root/c2ec/retrier.go
diff options
context:
space:
mode:
Diffstat (limited to 'c2ec/retrier.go')
-rw-r--r--c2ec/retrier.go55
1 files changed, 8 insertions, 47 deletions
diff --git a/c2ec/retrier.go b/c2ec/retrier.go
index d553708..a1ceee2 100644
--- a/c2ec/retrier.go
+++ b/c2ec/retrier.go
@@ -2,7 +2,6 @@ package main
import (
"context"
- "errors"
"strconv"
"time"
)
@@ -12,54 +11,16 @@ const PS_RETRY_CHANNEL = "retry"
func RunRetrier(ctx context.Context, errs chan error) {
- for _, p := range CONFIG.Providers {
- if PROVIDER_CLIENTS[p.Name] == nil {
- err := errors.New("no provider client initialized for provider " + p.Name)
- LogError("retrier", err)
- errs <- err
- }
- }
-
- notifications := make(chan *Notification, RETRY_CHANNEL_BUFFER_SIZE)
- go retryCallback(ctx, notifications, errs)
-}
-
-func retryCallback(ctx context.Context, notifications chan *Notification, errs chan error) {
-
- listener, err := NewListener(PS_RETRY_CHANNEL, notifications)
- if err != nil {
- LogError("retrier", err)
- errs <- errors.New("retrier needs to be setup first")
- }
-
- go func() {
- LogInfo("retrier", "retrier starts listening for retry notifications at the db")
- err := listener.Listen(ctx)
- if err != nil {
- LogError("retry-listener", err)
- errs <- err
- }
- close(notifications)
- close(errs)
- }()
-
- // Listen is started async. We can therefore block here and must
- // not run the retrieval logic in own goroutine
- for {
- select {
- case notification := <-notifications:
- // the dispatching and setup of the retry process can
- // be kicked off asynchronically, thus not blocking
- // further incoming notifications.
- go dispatchRetry(notification, errs)
- case <-ctx.Done():
- errs <- ctx.Err()
- return
- }
- }
+ go RunListener(
+ ctx,
+ PS_RETRY_CHANNEL,
+ retryCallback,
+ make(chan *Notification, RETRY_CHANNEL_BUFFER_SIZE),
+ errs,
+ )
}
-func dispatchRetry(n *Notification, errs chan error) {
+func retryCallback(n *Notification, errs chan error) {
withdrawalId, err := strconv.Atoi(n.Payload)
if err != nil {