Skip to content

Commit 614665f

Browse files
committed
Stop ping on inactive_account and invalid_auth.
1 parent 2692773 commit 614665f

File tree

5 files changed

+54
-139
lines changed

5 files changed

+54
-139
lines changed

.rubocop_todo.yml

Lines changed: 22 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -1,143 +1,56 @@
11
# This configuration was generated by
2-
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 1000`
3-
# on 2019-08-20 22:22:29 -0700 using RuboCop version 0.73.0.
2+
# `rubocop --auto-gen-config`
3+
# on 2019-12-23 15:50:03 -0500 using RuboCop version 0.73.0.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 5
9+
# Offense count: 3
1010
# Configuration parameters: AllowComments.
1111
Lint/HandleExceptions:
1212
Exclude:
1313
- 'lib/slack/real_time/concurrency/async.rb'
14-
- 'lib/slack_ruby_client.rb'
1514
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
1615
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
1716

18-
# Offense count: 9
19-
# Configuration parameters: Max.
17+
# Offense count: 10
2018
Metrics/AbcSize:
21-
Exclude:
22-
- 'lib/slack/real_time/client.rb'
23-
- 'lib/slack/real_time/concurrency/async.rb'
24-
- 'lib/slack/real_time/stores/store.rb'
25-
- 'lib/slack/web/api/mixins/users.search.rb'
26-
- 'lib/slack/web/faraday/connection.rb'
27-
- 'lib/slack/web/pagination/cursor.rb'
28-
- 'spec/integration/integration_spec.rb'
19+
Max: 39
2920

3021
# Offense count: 1
31-
# Configuration parameters: Max.
3222
Metrics/CyclomaticComplexity:
33-
Exclude:
34-
- 'lib/slack/web/faraday/connection.rb'
23+
Max: 9
3524

36-
# Offense count: 13
37-
# Configuration parameters: CountComments, Max, ExcludedMethods.
25+
# Offense count: 14
26+
# Configuration parameters: CountComments, ExcludedMethods.
3827
Metrics/MethodLength:
39-
Exclude:
40-
- 'lib/slack/messages/formatting.rb'
41-
- 'lib/slack/real_time/client.rb'
42-
- 'lib/slack/real_time/concurrency/async.rb'
43-
- 'lib/slack/real_time/concurrency/celluloid.rb'
44-
- 'lib/slack/real_time/config.rb'
45-
- 'lib/slack/real_time/stores/store.rb'
46-
- 'lib/slack/web/api/mixins/users.search.rb'
47-
- 'lib/slack/web/config.rb'
48-
- 'lib/slack/web/faraday/connection.rb'
49-
- 'lib/slack/web/faraday/request.rb'
50-
- 'lib/slack/web/pagination/cursor.rb'
51-
- 'spec/integration/integration_spec.rb'
28+
Max: 32
5229

5330
# Offense count: 1
54-
# Configuration parameters: Max.
5531
Metrics/PerceivedComplexity:
56-
Exclude:
57-
- 'lib/slack/web/faraday/connection.rb'
32+
Max: 9
5833

5934
# Offense count: 1
6035
RSpec/AnyInstance:
6136
Exclude:
6237
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
6338

64-
# Offense count: 69
39+
# Offense count: 70
6540
# Configuration parameters: Prefixes.
6641
# Prefixes: when, with, without
6742
RSpec/ContextWording:
68-
Exclude:
69-
- 'spec/integration/integration_spec.rb'
70-
- 'spec/slack/events/config_spec.rb'
71-
- 'spec/slack/events/request_spec.rb'
72-
- 'spec/slack/messages/formatting_spec.rb'
73-
- 'spec/slack/real_time/client_spec.rb'
74-
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
75-
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
76-
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
77-
- 'spec/slack/real_time/event_handlers/group_spec.rb'
78-
- 'spec/slack/real_time/event_handlers/im_spec.rb'
79-
- 'spec/slack/real_time/event_handlers/team_spec.rb'
80-
- 'spec/slack/real_time/event_handlers/user_spec.rb'
81-
- 'spec/slack/slack_spec.rb'
82-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
83-
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
84-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
85-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
86-
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
87-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
88-
- 'spec/slack/web/api/mixins/channels_spec.rb'
89-
- 'spec/slack/web/api/mixins/groups_spec.rb'
90-
- 'spec/slack/web/api/mixins/users_spec.rb'
91-
- 'spec/slack/web/api/pagination/cursor_spec.rb'
92-
- 'spec/slack/web/client_spec.rb'
93-
- 'spec/support/real_time/connected_client.rb'
43+
Enabled: false
9444

95-
# Offense count: 63
45+
# Offense count: 64
9646
# Configuration parameters: Max.
9747
RSpec/ExampleLength:
98-
Exclude:
99-
- 'spec/integration/integration_spec.rb'
100-
- 'spec/slack/real_time/client_spec.rb'
101-
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
102-
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
103-
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
104-
- 'spec/slack/real_time/event_handlers/group_spec.rb'
105-
- 'spec/slack/real_time/event_handlers/im_spec.rb'
106-
- 'spec/slack/real_time/event_handlers/team_spec.rb'
107-
- 'spec/slack/real_time/event_handlers/user_spec.rb'
108-
- 'spec/slack/slack_spec.rb'
109-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
110-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
111-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
112-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
113-
- 'spec/slack/web/api/error_spec.rb'
114-
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
115-
- 'spec/slack/web/api/errors/slack_error_spec.rb'
116-
- 'spec/slack/web/api/pagination/cursor_spec.rb'
117-
- 'spec/slack/web/client_spec.rb'
118-
- 'spec/slack/web/faraday/response/raise_error_spec.rb'
48+
Enabled: false
11949

120-
# Offense count: 16
50+
# Offense count: 17
12151
# Configuration parameters: CustomTransform, IgnoreMethods.
12252
RSpec/FilePath:
123-
Exclude:
124-
- 'spec/slack/real_time/api/message_spec.rb'
125-
- 'spec/slack/real_time/api/ping_spec.rb'
126-
- 'spec/slack/real_time/api/typing_spec.rb'
127-
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
128-
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
129-
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
130-
- 'spec/slack/real_time/event_handlers/group_spec.rb'
131-
- 'spec/slack/real_time/event_handlers/im_spec.rb'
132-
- 'spec/slack/real_time/event_handlers/user_spec.rb'
133-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
134-
- 'spec/slack/web/api/endpoints/custom_specs/channels_spec.rb'
135-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
136-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
137-
- 'spec/slack/web/api/endpoints/custom_specs/groups_spec.rb'
138-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
139-
- 'spec/slack/web/api/endpoints/custom_specs/views_spec.rb'
140-
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
53+
Enabled: false
14154

14255
# Offense count: 13
14356
# Configuration parameters: AssignmentOnly.
@@ -147,48 +60,20 @@ RSpec/InstanceVariable:
14760
- 'spec/slack/real_time/client_spec.rb'
14861
- 'spec/slack/slack_spec.rb'
14962

150-
# Offense count: 66
63+
# Offense count: 75
15164
# Configuration parameters: .
15265
# SupportedStyles: have_received, receive
15366
RSpec/MessageSpies:
15467
EnforcedStyle: receive
15568

156-
# Offense count: 92
157-
# Configuration parameters: Max, AggregateFailuresByDefault.
69+
# Offense count: 93
70+
# Configuration parameters: AggregateFailuresByDefault.
15871
RSpec/MultipleExpectations:
159-
Exclude:
160-
- 'spec/integration/integration_spec.rb'
161-
- 'spec/slack/events/config_spec.rb'
162-
- 'spec/slack/events/request_spec.rb'
163-
- 'spec/slack/real_time/client_spec.rb'
164-
- 'spec/slack/real_time/concurrency/celluloid_spec.rb'
165-
- 'spec/slack/real_time/concurrency/eventmachine_spec.rb'
166-
- 'spec/slack/real_time/event_handlers/bot_spec.rb'
167-
- 'spec/slack/real_time/event_handlers/channel_spec.rb'
168-
- 'spec/slack/real_time/event_handlers/event_handlers_spec.rb'
169-
- 'spec/slack/real_time/event_handlers/group_spec.rb'
170-
- 'spec/slack/real_time/event_handlers/im_spec.rb'
171-
- 'spec/slack/real_time/event_handlers/team_spec.rb'
172-
- 'spec/slack/real_time/event_handlers/user_spec.rb'
173-
- 'spec/slack/real_time/store_spec.rb'
174-
- 'spec/slack/slack_spec.rb'
175-
- 'spec/slack/web/api/endpoints/custom_specs/auth_spec.rb'
176-
- 'spec/slack/web/api/endpoints/custom_specs/chat_spec.rb'
177-
- 'spec/slack/web/api/endpoints/custom_specs/dialog_spec.rb'
178-
- 'spec/slack/web/api/endpoints/custom_specs/users_spec.rb'
179-
- 'spec/slack/web/api/error_spec.rb'
180-
- 'spec/slack/web/api/errors/service_unavailable_spec.rb'
181-
- 'spec/slack/web/api/errors/slack_error_spec.rb'
182-
- 'spec/slack/web/api/pagination/cursor_spec.rb'
183-
- 'spec/slack/web/client_spec.rb'
72+
Max: 5
18473

185-
# Offense count: 32
186-
# Configuration parameters: Max.
74+
# Offense count: 34
18775
RSpec/NestedGroups:
188-
Exclude:
189-
- 'spec/slack/real_time/client_spec.rb'
190-
- 'spec/slack/web/api/pagination/cursor_spec.rb'
191-
- 'spec/slack/web/client_spec.rb'
76+
Max: 6
19277

19378
# Offense count: 3
19479
RSpec/SubjectStub:

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* [#297](https://github.com/slack-ruby/slack-ruby-client/pull/297): Various Rubocop fixes - [@jcraigk](https://github.com/jcraigk).
55
* [#298](https://github.com/slack-ruby/slack-ruby-client/pull/298): Add `admin.apps`, `admin.app.requests` and `views` endpoints - [@jmanian](https://github.com/jmanian).
66
* [#302](https://github.com/slack-ruby/slack-ruby-client/pull/302): Add `oauth.v2.access` and `views.published` endpoints - [@jwright](https://github.com/jwright).
7+
* [#309](https://github.com/slack-ruby/slack-ruby-client/pull/309): Stop ping on `inactive_account` and `invalid_auth` - [@dblock](https://github.com/dblock).
78
* Your contribution here.
89

910
### 0.14.4 (2019/7/28)

lib/slack/real_time/client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,14 @@ def run_ping!
131131
logger.warn(to_s) { 'is offline' }
132132

133133
restart_async
134+
rescue Slack::Web::Api::Errors::SlackError => e
135+
# stop pinging if bot was uninstalled
136+
case e.message
137+
when 'account_inactive', 'invalid_auth' then
138+
logger.warn(to_s) { e.message }
139+
raise e
140+
end
141+
logger.debug("#{self}##{__method__}") { e }
134142
rescue StandardError => e
135143
# disregard all ping worker failures, keep pinging
136144
logger.debug("#{self}##{__method__}") { e }

lib/slack/web/api/errors/slack_error.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ class SlackError < ::Faraday::Error
77
attr_reader :response
88

99
def initialize(message, response = nil)
10-
@response = response
1110
super message
11+
@response = response
1212
end
1313
end
1414
end

spec/slack/real_time/client_spec.rb

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,13 @@
193193
expect(socket).to receive(:restart_async)
194194
client.run_ping!
195195
end
196-
[EOFError, Errno::ECONNRESET, Errno::EPIPE, Faraday::ClientError].each do |err|
196+
[
197+
EOFError,
198+
Errno::ECONNRESET,
199+
Errno::EPIPE,
200+
Faraday::ClientError,
201+
Slack::Web::Api::Errors::SlackError
202+
].each do |err|
197203
context "raising #{err}" do
198204
it 'does not terminate the ping worker' do
199205
allow(socket).to receive(:time_since_last_message) { raise err }
@@ -202,6 +208,21 @@
202208
end
203209
end
204210
end
211+
context 'raising Slack::Web::Api::Errors::SlackError' do
212+
%w[invalid_auth account_inactive].each do |code|
213+
context code do
214+
it 'does not terminate the ping worker' do
215+
allow(socket).to receive(:time_since_last_message) {
216+
raise Slack::Web::Api::Errors::SlackError, code
217+
}
218+
expect(socket).not_to receive(:send_data)
219+
expect do
220+
client.run_ping!
221+
end.to raise_error Slack::Web::Api::Errors::SlackError, code
222+
end
223+
end
224+
end
225+
end
205226
end
206227
end
207228

0 commit comments

Comments
 (0)