Sha256: f7e8e8b6deae34b185811f1d110a7f9046f17a1fcc5a7f383ba5a51cb1c25650

Contents?: true

Size: 1.4 KB

Versions: 14

Compression:

Stored size: 1.4 KB

Contents

module Flydata
  module Helper
    class ActionOwnership
      attr_accessor :action_name

      # Resource change flag
      # true -> action must be taken exclusively
      attr_accessor :resource_change

      # action_class has a actual logic
      attr_accessor :action_class

      # Owner should be nil(channel) or worker
      attr_accessor :owner

      # last processeed time should be updated when worker return
      # action ownership to channel
      attr_accessor :last_processed_time

      attr_accessor :retry_count

      def initialize(action_name, resource_change = false, action_class = nil)
        @action_name = action_name
        @resource_change = resource_change
        @action_class = action_class
        @owner = nil
        @last_processed_time = -1
        @retry_count = 0
      end

      def processing?
        !@owner.nil?
      end

      def reset_retry_count
        @retry_count = 0
      end

      def increment_retry_count
        @retry_count += 1
      end

      def self.action_ownership_map
        [
          self.new(:check_remote_actions, false, Action::CheckRemoteActions),
          self.new(:send_logs, false, Action::SendLogs),
          self.new(:stop_agent, true, Action::StopAgent),
          self.new(:restart_agent, true, Action::RestartAgent)
        ].inject({}) do |h, action|
          h[action.action_name] = action
          h
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
flydata-0.5.9 lib/flydata/helper/action_ownership.rb
flydata-0.5.8 lib/flydata/helper/action_ownership.rb
flydata-0.5.7 lib/flydata/helper/action_ownership.rb
flydata-0.5.6 lib/flydata/helper/action_ownership.rb
flydata-0.5.5 lib/flydata/helper/action_ownership.rb
flydata-0.5.4 lib/flydata/helper/action_ownership.rb
flydata-0.5.3 lib/flydata/helper/action_ownership.rb
flydata-0.5.2 lib/flydata/helper/action_ownership.rb
flydata-0.5.1 lib/flydata/helper/action_ownership.rb
flydata-0.5.0 lib/flydata/helper/action_ownership.rb
flydata-0.4.3 lib/flydata/helper/action_ownership.rb
flydata-0.4.2 lib/flydata/helper/action_ownership.rb
flydata-0.4.1 lib/flydata/helper/action_ownership.rb
flydata-0.4.0 lib/flydata/helper/action_ownership.rb