Sha256: 0ef8769a884646576f5e2e4172bd562ac944926cd5961e67fd161ae5156dc4d6

Contents?: true

Size: 1003 Bytes

Versions: 1

Compression:

Stored size: 1003 Bytes

Contents

# frozen_string_literal: true

require 'httparty'
require 'no_proxy_fix'
require 'slack-notifier'

module MShard
  class MShard
    include HTTParty
    base_uri ENV['MSHARD_URI']

    def get(id)
      self.class.get("/v2/shards/#{id}").body
    end

    def set(params)
      self.class.post('/v2/shards', body: params)['id']
    end

    def try(times: 3, delay: 2)
      times.times do
        begin
          return yield
        rescue StandardError
          sleep delay
        end
      end
      nil
    end

    def get_safe(*args)
      try { get(*args) }
    end

    def set_safe(*args) # rubocop:disable Naming/AccessorMethodName
      try { set(*args) }
    end

    def detour?
      ENV['http_proxy']
    end

    def notify(**args)
      args[:slack] ||= true
      args[:webhook_url] ||= ENV['SLACK_WEBHOOK_URI']
      args[:channel] ||= ENV['SLACK_CHANNEL']
      return set(args) if detour?
      Slack::Notifier.new(args[:webhook_url], **args).ping(args[:text])
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mshard-0.6.1 lib/mshard/mshard.rb