class OpenwifiResetAccessTokenWorker
  include Sidekiq::Worker
  sidekiq_options :queue => :openwifi_token_reset, :retry => 3, :backtrace => true
 
  def perform
    int_types = IntegrationType.where(vendor_name: 'openwifi')
    [int_types.all,nil].flatten.each do |int_type|
      # openwifi_token = $redis.hgetall "OPENWIFI:SDK:USER:#{int_type.id}"
      openwifi_token = $redis.hgetall (int_type.present? ? "OPENWIFI:SDK:USER:#{int_type.id}" : 'OPENWIFI:SDK:USER')
      if(openwifi_token['created_at'].present? && openwifi_token['expires_in'].present? && (Time.now - 1.day).to_i > (openwifi_token['created_at'].to_i + openwifi_token['expires_in'].to_i))
        puts "[OPENWIFI][ACCESS TOKEN RESET] :: INT TYPE (#{int_type})"
        res = OpenWifi::SecurityService.new(int_type).oauth2
      end
    end
  end
end