Skip to content

Commit 30b72ca

Browse files
committed
Slack: on 429 response to rtm.connect, wait before trying again
1 parent 03519d5 commit 30b72ca

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

lib/Synergy/External/Slack.pm

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,24 @@ has pending_timeouts => (
127127
async sub connect ($self) {
128128
$self->connected(0);
129129

130-
my $res = await $self->hub->http_client->GET(
131-
"https://slack.com/api/rtm.connect?token=" . $self->api_key
132-
);
130+
my $json;
133131

134-
my $json = decode_json($res->content);
132+
until ($json) {
133+
my $res = await $self->hub->http_client->GET(
134+
"https://slack.com/api/rtm.connect?token=" . $self->api_key
135+
);
135136

136-
die "Could not connect to Slack RTM: $json->{error}"
137-
unless $json->{ok};
137+
if ($res->code == 429) {
138+
$Logger->log('received 429 while connecting to Slack; will try again in 120s');
139+
await $self->loop->delay_future(after => 120);
140+
next;
141+
}
142+
143+
my $json = decode_json($res->content);
144+
145+
die "Could not connect to Slack RTM: $json->{error}"
146+
unless $json->{ok};
147+
}
138148

139149
# This is a dumb hack: when I converted synergy to a Slack app, I gave her
140150
# perms to add a user with the name "synergee" because I thought "synergy"

0 commit comments

Comments
 (0)