require 'travis/addons/handlers/base'
require 'travis/addons/handlers/task'
require 'travis/addons/model/broadcast'
require 'travis/rollout'
require 'zlib'

module Travis
  module Addons
    module Handlers
      class LogSearch < Base
        include Handlers::Task

        # alias logsearch => log_search
        Event::Handler.register('logsearch', self)

        EVENTS = 'job:finished'

        def handle?
          return false unless ENV['LOGSEARCH_ENABLED'] == 'true'

          # random uid to sample randomly (not tied to user)
          Rollout.matches?(:logsearch, {
            uid:   Zlib.crc32(SecureRandom.hex),
            owner: object.repository.owner.login,
            repo:  object.repository.slug,
            redis: Travis::Hub.context.redis
          })
        end

        def handle
          Travis::Sidekiq.logsearch(object.id)
        end

        private

          def payload
            object.id
          end

          class EventHandler < Addons::Instrument
            def notify_completed
              publish
            end
          end
          EventHandler.attach_to(self)
      end
    end
  end
end

require 'travis/addons/handlers/base'
require 'travis/addons/handlers/task'
require 'travis/addons/model/broadcast'
require 'travis/rollout'

module Travis
  module Addons
    module Handlers
      class LogSearch < Base
        include Handlers::Task

        # alias logsearch => log_search
        Event::Handler.register('logsearch', self)

        EVENTS = 'job:finished'

        def handle?
          return false unless ENV['LOGSEARCH_ENABLED'] == 'true'

          # random uid to sample randomly (not tied to user)
          Rollout.matches?(:logsearch, {
            uid:   SecureRandom.hex,
            owner: object.repository.owner.login,
            repo:  object.repository.slug,
            redis: Travis::Hub.context.redis
          })
        end

        def handle
          Travis::Sidekiq.logsearch(object.id)
        end

        private

          def payload
            object.id
          end

          class EventHandler < Addons::Instrument
            def notify_completed
              publish
            end
          end
          EventHandler.attach_to(self)
      end
    end
  end
end

Revert "make sure (random) uid is an int"
Revert "make sure (random) uid is an int"

This is already handled by travis-rollout.

This reverts commit c86be9d78b03e2be6010270c2bb484be7e0483bc.
