Sha256: d54e785cecf5e00a186190301d88b5ab382c84ef132e0ab71d2f1be288245300

Contents?: true

Size: 1.25 KB

Versions: 1

Compression:

Stored size: 1.25 KB

Contents

require 'sleepiq'

module Legion::Extensions::Sleepiq
  module Helpers
    module Client
      def client(**_opts)
        @awsalb = Legion::Cache.get('sleepiq_awsalb')
        @bedid = Legion::Cache.get('sleepiq_bedid')
        @key = Legion::Cache.get('sleepiq_key')
        @sessid = Legion::Cache.get('sleepiq_sessid')

        login if @awsalb.nil? || @key.nil? || @sessid.nil?
        ::SleepIQ::Client.new(awsalb: @awsalb, key: @key, sessid: @sessid, bedid: @bedid)
      rescue StandardError => e
        Legion::Logging.fatal e.message
        Legion::Logging.fatal e.backtrace
        raise(e)
      end

      def login
        result = ::SleepIQ::Client.new(username: username, password: password)
        Legion::Cache.set('sleepiq_sessid', result.sessid, 600)
        @sessid = result.sessid
        Legion::Cache.set('sleepiq_awsalb', result.awsalb, 600)
        @awsalb = result.awsalb
        Legion::Cache.set('sleepiq_key', result.key, 600)
        @key = result.key
        Legion::Cache.set('sleepiq_bedid', result.bedid, 600)
        @bedid = result.bedid
      end

      def username(**opts)
        @username = find_setting('username', opts)
      end

      def password(**opts)
        @password = find_setting('password', opts)
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lex-sleepiq-0.1.0 lib/legion/extensions/sleepiq/helpers/client.rb