Skip to content

Commit 3195e17

Browse files
authored
fix: resubscribe subsystems when their subscription is terminated (#593)
Fixes #577 The events broker can legitimately terminate the subscription of a subscriber, e.g. when the subscriber's event queue is full up. Various subsystems such as the scheduler would, in such a scenario, simply shutdown. Which in the case of #577 would mean no more runs could be started. This PR changes the behaviour of the subsystems: when their subscription is terminated, they instead return an error, which triggers the subsystem to be restarted (using a backoff algorithm) rather than stop completely.
1 parent 346024e commit 3195e17

File tree

6 files changed

+10
-5
lines changed

6 files changed

+10
-5
lines changed

internal/logs/proxy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func (p *proxy) Start(ctx context.Context) error {
7777
p.Error(err, "caching log chunk")
7878
}
7979
}
80-
return nil
80+
return pubsub.ErrSubscriptionTerminated
8181
}
8282

8383
// GetChunk attempts to retrieve a chunk from the cache before falling back to

internal/notifications/notifier.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func (s *Notifier) Start(ctx context.Context) error {
7272
s.Error(err, "handling event", "event", event.Type)
7373
}
7474
}
75-
return nil
75+
return pubsub.ErrSubscriptionTerminated
7676
}
7777

7878
func (s *Notifier) handle(ctx context.Context, event pubsub.Event) error {

internal/pubsub/broker.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package pubsub
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"sync"
89

@@ -22,6 +23,10 @@ const (
2223
subBufferSize = 100
2324
)
2425

26+
// ErrSubscriptionTerminated is for use by subscribers to indicate that their
27+
// subscription has been terminated by the broker.
28+
var ErrSubscriptionTerminated = errors.New("broker terminated the subscription")
29+
2530
type (
2631

2732
// Broker is a pubsub Broker implemented using postgres' listen/notify

internal/repo/purger.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (p *Purger) Start(ctx context.Context) error {
7070
return err
7171
}
7272
}
73-
return nil
73+
return pubsub.ErrSubscriptionTerminated
7474
}
7575

7676
func (p *Purger) deleteUnreferencedWebhooks(ctx context.Context) error {

internal/run/reporter.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ func (r *Reporter) Start(ctx context.Context) error {
6464
return err
6565
}
6666
}
67-
return nil
67+
return pubsub.ErrSubscriptionTerminated
6868
}
6969

7070
func (r *Reporter) handleRun(ctx context.Context, run *Run) error {

internal/scheduler/scheduler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,5 @@ func (s *scheduler) Start(ctx context.Context) error {
151151
}
152152
}
153153
}
154-
return nil
154+
return pubsub.ErrSubscriptionTerminated
155155
}

0 commit comments

Comments
 (0)