Class: Rage::Configuration::Deferred

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/configuration.rb

Defined Under Namespace

Classes: Backpressure

Instance Method Summary collapse

Instance Method Details

#backendObject

Returns the backend instance used by Rage::Deferred.



610
611
612
613
614
615
616
617
# File 'lib/rage/configuration.rb', line 610

def backend
  unless @backend_class
    @backend_class = Rage::Deferred::Backends::Disk
    @backend_options = parse_disk_backend_options({})
  end

  @backend_class.new(**@backend_options)
end

#backend=(disk, options = {}) ⇒ Object #backend=(nil) ⇒ Object

Specify the backend used to persist deferred tasks. Supported values are :disk, which uses disk storage, or nil, which disables persistence of deferred tasks.

Overloads:

  • #backend=(disk, options = {}) ⇒ Object

    Use the disk backend.

    Examples:

    Use the disk backend with default options

    Rage.configure do
      config.deferred.backend = :disk
    end

    Use the disk backend with custom options

    Rage.configure do
      config.deferred.backend = :disk, path: "my_storage", fsync_frequency: 1000
    end

    Parameters:

    • options (Hash) (defaults to: {})

      additional backend options

    Options Hash (options):

    • :path (Pathname, String)

      the directory where deferred tasks will be stored. Defaults to storage/

    • :prefix (String)

      the prefix used for deferred task files. Defaults to deferred-

    • :fsync_frequency (Integer)

      the frequency of fsync calls in seconds. Defaults to 0.5

  • #backend=(nil) ⇒ Object

    Disable persistence of deferred tasks.

    Examples:

    Rage.configure do
      config.deferred.backend = nil
    end


640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
# File 'lib/rage/configuration.rb', line 640

def backend=(config)
  @configured = true

  backend_id, opts = if config.is_a?(Array)
    [config[0], config[1]]
  else
    [config, {}]
  end

  @backend_class = case backend_id
  when :disk
    @backend_options = parse_disk_backend_options(opts)
    Rage::Deferred::Backends::Disk
  when nil
    Rage::Deferred::Backends::Nil
  else
    raise ArgumentError, "unsupported backend value; supported keys are `:disk` and `nil`"
  end
end

#backpressureBackpressure?

Returns the backpressure configuration used by Rage::Deferred.

Returns:



676
677
678
# File 'lib/rage/configuration.rb', line 676

def backpressure
  @backpressure
end

#backpressure=(true) ⇒ Object #backpressure=(false) ⇒ Object #backpressure=(config) ⇒ Object

Configure backpressure settings for Rage::Deferred. Backpressure is used to limit the number of pending tasks in the queue and is disabled by default.

Overloads:

  • #backpressure=(true) ⇒ Object

    Enable backpressure with default settings.

    Examples:

    Rage.configure do
      config.deferred.backpressure = true
    end
  • #backpressure=(false) ⇒ Object

    Disable backpressure.

    Examples:

    Rage.configure do
      config.deferred.backpressure = false
    end
  • #backpressure=(config) ⇒ Object

    Enable backpressure with custom settings.

    Examples:

    Rage.configure do
      config.deferred.backpressure = { high_water_mark: 2000, low_water_mark: 1500, timeout: 5 }
    end

    Parameters:

    • config (Hash)

      backpressure configuration

    Options Hash (config):

    • :high_water_mark (Integer)

      the maximum number of deferred tasks allowed in the queue before applying backpressure. Defaults to 1000.

    • :low_water_mark (Integer)

      the minimum number of deferred tasks in the queue at which backpressure is lifted. Defaults to 80% of :high_water_mark.

    • :timeout (Integer)

      the maximum time in seconds to wait for the queue size to drop below :low_water_mark before raising the Rage::Deferred::PushTimeout exception. Defaults to 2 seconds.



706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
# File 'lib/rage/configuration.rb', line 706

def backpressure=(config)
  @configured = true

  if config == true
    @backpressure = Backpressure.new
    return
  elsif config == false
    @backpressure = nil
    return
  end

  if config.except(:high_water_mark, :low_water_mark, :timeout).any?
    raise ArgumentError, "unsupported backpressure options; supported keys are `:high_water_mark`, `:low_water_mark`, `:timeout`"
  end

  high_water_mark, low_water_mark, timeout = config.values_at(:high_water_mark, :low_water_mark, :timeout)
  @backpressure = Backpressure.new(high_water_mark, low_water_mark, timeout)
end