From 88528f28c6c525b0ca4a05cf19e97cce4c49ecf6 Mon Sep 17 00:00:00 2001 From: Nicholas Koh Date: Thu, 21 Jan 2021 21:26:28 +0800 Subject: [PATCH] Remove faye Add changelog Remove faye from CI Improve readme --- .rubocop_todo.yml | 14 --- .travis.yml | 2 - CHANGELOG.md | 4 +- README.md | 17 +--- .../hi_real_time_async_eventmachine/Gemfile | 7 -- .../hi_real_time_async_eventmachine/Procfile | 2 - .../hi_real_time_async_eventmachine/hi.rb | 39 --------- lib/slack/real_time/concurrency.rb | 1 - .../real_time/concurrency/eventmachine.rb | 85 ------------------- lib/slack/real_time/config.rb | 2 +- lib/slack/web/api/slack-api-ref | 2 +- .../concurrency/eventmachine_spec.rb | 57 ------------- 12 files changed, 7 insertions(+), 225 deletions(-) delete mode 100644 examples/hi_real_time_async_eventmachine/Gemfile delete mode 100644 examples/hi_real_time_async_eventmachine/Procfile delete mode 100644 examples/hi_real_time_async_eventmachine/hi.rb delete mode 100644 lib/slack/real_time/concurrency/eventmachine.rb delete mode 100644 spec/slack/real_time/concurrency/eventmachine_spec.rb diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 285992b8..72bf5778 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -18,13 +18,6 @@ Lint/RedundantCopDisableDirective: Exclude: - 'lib/slack-ruby-client.rb' -# Offense count: 2 -# Configuration parameters: AllowComments. -Lint/SuppressedException: - Exclude: - - 'spec/slack/real_time/concurrency/celluloid_spec.rb' - - 'spec/slack/real_time/concurrency/eventmachine_spec.rb' - # Offense count: 11 # Configuration parameters: IgnoredMethods. Metrics/AbcSize: @@ -56,11 +49,6 @@ Performance/RegexpMatch: Exclude: - 'lib/tasks/web.rake' -# Offense count: 1 -RSpec/AnyInstance: - Exclude: - - 'spec/slack/real_time/concurrency/celluloid_spec.rb' - # Offense count: 5 # Cop supports --auto-correct. RSpec/ContextMethod: @@ -134,8 +122,6 @@ RSpec/VerifiedDoubles: Exclude: - 'spec/slack/events/request_spec.rb' - 'spec/slack/real_time/client_spec.rb' - - 'spec/slack/real_time/concurrency/celluloid_spec.rb' - - 'spec/slack/real_time/concurrency/eventmachine_spec.rb' - 'spec/slack/web/faraday/response/raise_error_spec.rb' - 'spec/support/real_time/connected_client.rb' diff --git a/.travis.yml b/.travis.yml index b004d90a..fb0e0609 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,8 +14,6 @@ matrix: - rvm: 2.4.1 script: - bundle exec danger - - rvm: 2.4.1 - env: CONCURRENCY=faye-websocket - rvm: 2.5.3 env: CONCURRENCY=async-websocket allow_failures: diff --git a/CHANGELOG.md b/CHANGELOG.md index 75aaf84a..5e7fb124 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,10 @@ ### 0.16.0 (Next) * [#350](https://github.com/slack-ruby/slack-ruby-client/pull/350): Handle server errors such as timouts & non-json responses (see [Upgrading to 0.16.0](UPGRADING.md#upgrading-to--0160)) - [@ojab](https://github.com/ojab). +* [#348](https://github.com/slack-ruby/slack-ruby-client/pull/348): Added `admin_conversations_archive`, `admin_conversations_convertToPrivate`, `admin_conversations_create`, `admin_conversations_delete`, `admin_conversations_disconnectShared`, `admin_conversations_getConversationPrefs`, `admin_conversations_getTeams`, `admin_conversations_invite`, `admin_conversations_rename`, `admin_conversations_search`, `admin_conversations_setConversationPrefs`, `admin_conversations_unarchive`, `admin_conversations_ekm_listOriginalConnectedChannelInfo`, `admin_users_session_invalidate`, `apps_event_authorizations_list`, `conversations_mark`, `workflows_stepCompleted`, `workflows_stepFailed` and `workflows_updateStep` endpoints - [@wasabigeek](https://github.com/wasabigeek). * [#354](https://github.com/slack-ruby/slack-ruby-client/pull/354): Rewind body after checking request signature - [@sunny](https://github.com/sunny). -* [#355](https://github.com/slack-ruby/slack-ruby-client/pull/355): Removed celluloid concurrency support - [@wasabigeek](https://github.com/wasabigeek). +* [#355](https://github.com/slack-ruby/slack-ruby-client/pull/355), [#357](https://github.com/slack-ruby/slack-ruby-client/pull/357): Remove celluloid and faye-websocket support - [@wasabigeek](https://github.com/wasabigeek). * [#356](https://github.com/slack-ruby/slack-ruby-client/pull/356): Added `admin_apps_clearResolution`, `admin_conversations_getCustomRetention`, `admin_conversations_removeCustomRetention`, `admin_conversations_setCustomRetention` and `admin_users_session_list` endpoints - [@dblock](https://github.com/dblock). -* [#348](https://github.com/slack-ruby/slack-ruby-client/pull/348): Added `admin_conversations_archive`, `admin_conversations_convertToPrivate`, `admin_conversations_create`, `admin_conversations_delete`, `admin_conversations_disconnectShared`, `admin_conversations_getConversationPrefs`, `admin_conversations_getTeams`, `admin_conversations_invite`, `admin_conversations_rename`, `admin_conversations_search`, `admin_conversations_setConversationPrefs`, `admin_conversations_unarchive`, `admin_conversations_ekm_listOriginalConnectedChannelInfo`, `admin_users_session_invalidate`, `apps_event_authorizations_list`, `conversations_mark`, `workflows_stepCompleted`, `workflows_stepFailed` and `workflows_updateStep` endpoints - [@wasabigeek](https://github.com/wasabigeek). * Your contribution here. ### 0.15.1 (2020/9/3) diff --git a/README.md b/README.md index 9b7316e8..60d36bbd 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,6 @@ A Ruby client for the Slack [Web](https://api.slack.com/web), [RealTime Messagin - [Large Team Considerations](#large-team-considerations) - [Concurrency](#concurrency) - [Async](#async) - - [Faye::Websocket with Eventmachine](#fayewebsocket-with-eventmachine) - [Events API](#events-api) - [Configuring Slack::Events](#configuring-slackevents) - [Verifying the Request Signature](#verifying-the-request-signature) @@ -81,7 +80,7 @@ Add to Gemfile. gem 'slack-ruby-client' ``` -If you're going to be using the RealTime client, add either `async-websocket`, `eventmachine` and `faye-websocket`. See below for more information about concurrency. We recommend you use `async-websocket`. +If you're going to be using the RealTime client, add `async-websocket`. See below for more information about concurrency. ``` gem 'async-websocket', '~> 0.8.0' @@ -494,7 +493,7 @@ See [#134](https://github.com/slack-ruby/slack-ruby-client/issues/134) for a dis #### Concurrency -`Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async) and [Faye::WebSocket](https://github.com/faye/faye-websocket-ruby) with [Eventmachine](https://github.com/eventmachine/eventmachine). It will auto-detect one or the other depending on the gems in your Gemfile, but you can also set concurrency explicitly. +`Slack::RealTime::Client` needs help from a concurrency library and supports [Async](https://github.com/socketry/async). ```ruby Slack::RealTime.configure do |config| @@ -512,7 +511,7 @@ client.start_async ##### Async -This is the recommended library. Add `async-websocket` to your Gemfile. +Add `async-websocket` to your Gemfile. ``` gem 'async-websocket' @@ -520,16 +519,6 @@ gem 'async-websocket' See a fully working example in [examples/hi_real_time_async_async](examples/hi_real_time_async_async/hi.rb). -##### Faye::Websocket with Eventmachine - -Add the following to your Gemfile. - -``` -gem 'faye-websocket' -``` - -See a fully working example in [examples/hi_real_time_async_eventmachine](examples/hi_real_time_async_eventmachine/hi.rb). - ### Events API This library provides limited support for the [Slack Events API](https://api.slack.com/events-api). diff --git a/examples/hi_real_time_async_eventmachine/Gemfile b/examples/hi_real_time_async_eventmachine/Gemfile deleted file mode 100644 index ca94707e..00000000 --- a/examples/hi_real_time_async_eventmachine/Gemfile +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true -source 'http://rubygems.org' - -gem 'slack-ruby-client', path: '../..' - -gem 'faye-websocket' -gem 'foreman' diff --git a/examples/hi_real_time_async_eventmachine/Procfile b/examples/hi_real_time_async_eventmachine/Procfile deleted file mode 100644 index 8f831a3a..00000000 --- a/examples/hi_real_time_async_eventmachine/Procfile +++ /dev/null @@ -1,2 +0,0 @@ -console: bundle exec ruby hi.rb - diff --git a/examples/hi_real_time_async_eventmachine/hi.rb b/examples/hi_real_time_async_eventmachine/hi.rb deleted file mode 100644 index 7053e607..00000000 --- a/examples/hi_real_time_async_eventmachine/hi.rb +++ /dev/null @@ -1,39 +0,0 @@ -# frozen_string_literal: true -require 'slack-ruby-client' - -raise 'Missing ENV[SLACK_API_TOKENS]!' unless ENV.key?('SLACK_API_TOKENS') - -$stdout.sync = true -logger = Logger.new($stdout) -logger.level = Logger::DEBUG -threads = [] - -ENV['SLACK_API_TOKENS'].split.each do |token| - logger.info "Starting #{token[0..12]} ..." - - client = Slack::RealTime::Client.new(token: token) - - client.on :hello do - logger.info( - "Successfully connected, welcome '#{client.self.name}' to " \ - "the '#{client.team.name}' team at https://#{client.team.domain}.slack.com." - ) - end - - client.on :message do |data| - logger.info data - - client.typing channel: data.channel - - case data.text - when 'bot hi' - client.message channel: data.channel, text: "Hi <@#{data.user}>!" - when /^bot/ - client.message channel: data.channel, text: "Sorry <@#{data.user}>, what?" - end - end - - threads << client.start_async -end - -threads.each(&:join) diff --git a/lib/slack/real_time/concurrency.rb b/lib/slack/real_time/concurrency.rb index 133a0aa6..9bfd79d1 100644 --- a/lib/slack/real_time/concurrency.rb +++ b/lib/slack/real_time/concurrency.rb @@ -3,7 +3,6 @@ module Slack module RealTime module Concurrency autoload :Async, 'slack/real_time/concurrency/async' - autoload :Eventmachine, 'slack/real_time/concurrency/eventmachine' end end end diff --git a/lib/slack/real_time/concurrency/eventmachine.rb b/lib/slack/real_time/concurrency/eventmachine.rb deleted file mode 100644 index 4249df88..00000000 --- a/lib/slack/real_time/concurrency/eventmachine.rb +++ /dev/null @@ -1,85 +0,0 @@ -# frozen_string_literal: true -require 'faye/websocket' -require 'eventmachine' - -module Slack - module RealTime - module Concurrency - module Eventmachine - class Client < Faye::WebSocket::Client - def initialize(url, protocols = nil, options = {}) - options = options.dup - @logger = options.delete(:logger) || Slack::RealTime::Config.logger || Slack::Config.logger - super url, protocols, options - end - - def parse(data) - logger.debug("#{self.class}##{__method__}") { data } - super data - end - - def write(data) - logger.debug("#{self.class}##{__method__}") { data } - super data - end - - protected - - attr_reader :logger - end - - class Socket < Slack::RealTime::Socket - def start_async(client) - @thread = ensure_reactor_running - - if client.run_ping? - EventMachine.add_periodic_timer client.websocket_ping_timer do - client.run_ping! - end - end - - client.run_loop - - @thread - end - - def restart_async(client, new_url) - @url = new_url - @last_message_at = current_time - @thread = ensure_reactor_running - - client.run_loop - - @thread - end - - def disconnect! - super - EventMachine.stop_event_loop if EventMachine.reactor_running? - @thread = nil - end - - def send_data(message) - logger.debug("#{self.class}##{__method__}") { message } - driver.send(message) - end - - protected - - # @return [Thread] - def ensure_reactor_running - return if EventMachine.reactor_running? - - reactor = Thread.new { EventMachine.run } - Thread.pass until EventMachine.reactor_running? - reactor - end - - def connect - @driver = Client.new(url, nil, options.merge(logger: logger)) - end - end - end - end - end -end diff --git a/lib/slack/real_time/config.rb b/lib/slack/real_time/config.rb index 989871fd..ba90af73 100644 --- a/lib/slack/real_time/config.rb +++ b/lib/slack/real_time/config.rb @@ -38,7 +38,7 @@ def concurrency private def detect_concurrency - %i[Async Eventmachine].each do |concurrency| + %i[Async].each do |concurrency| begin return Slack::RealTime::Concurrency.const_get(concurrency) rescue LoadError, NameError diff --git a/lib/slack/web/api/slack-api-ref b/lib/slack/web/api/slack-api-ref index 944bb458..e9d1be57 160000 --- a/lib/slack/web/api/slack-api-ref +++ b/lib/slack/web/api/slack-api-ref @@ -1 +1 @@ -Subproject commit 944bb458c254251fc47a9fef9185d629b8332e86 +Subproject commit e9d1be57a1ec0dbbfe807e263741d7e6ea655eb5 diff --git a/spec/slack/real_time/concurrency/eventmachine_spec.rb b/spec/slack/real_time/concurrency/eventmachine_spec.rb deleted file mode 100644 index 166212f0..00000000 --- a/spec/slack/real_time/concurrency/eventmachine_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -# frozen_string_literal: true -require 'spec_helper' -require_relative './it_behaves_like_a_realtime_socket' - -begin - RSpec.describe Slack::RealTime::Concurrency::Eventmachine::Socket do - it_behaves_like 'a realtime socket' - context 'with url' do - let(:url) { 'wss://ms174.slack-msgs.com/websocket/xyz' } - let(:logger) { ::Logger.new($stdout) } - let(:socket) { described_class.new(url, ping: 42, logger: logger) } - let(:ws) { double(Faye::WebSocket::Client) } - - describe '#connect!' do - before do - allow(ws).to receive(:on).with(:close) - allow(ws).to receive(:on).with(:message) - end - - it 'connects' do - allow(Faye::WebSocket::Client).to receive(:new).and_return(ws) - socket.connect! - expect(socket.instance_variable_get('@driver')).to eq ws - end - it 'pings every 30s' do - expect(Faye::WebSocket::Client).to( - receive(:new).with(url, nil, ping: 42, logger: logger).and_return(ws) - ) - socket.connect! - end - end - - describe '#disconnect!' do - it 'closes and nils the websocket' do - socket.instance_variable_set('@driver', ws) - expect(ws).to receive(:emit).with(:close) - expect(ws).to receive(:close) - socket.disconnect! - end - end - - describe 'send_data' do - before do - allow(Faye::WebSocket::Client).to receive(:new).and_return(ws) - allow(ws).to receive(:on) - socket.connect! - end - - it 'sends data' do - expect(ws).to receive(:send).with('data') - socket.send_data('data') - end - end - end - end -rescue LoadError -end