Class: Rage::Configuration::Deferred

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

Defined Under Namespace

Classes: Backpressure, Middleware

Instance Method Summary collapse

Instance Method Details

#backendObject

Returns the backend instance used by Rage::Deferred.



661
662
663
664
665
666
667
668
# File 'lib/rage/configuration.rb', line 661

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


691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/rage/configuration.rb', line 691

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:



727
728
729
# File 'lib/rage/configuration.rb', line 727

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.



757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
# File 'lib/rage/configuration.rb', line 757

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

#enqueue_middlewareRage::Configuration::Deferred::Middleware

Configure enqueue middleware used by Rage::Deferred. See EnqueueMiddlewareInterface for details on the arguments passed to the middleware.

Examples:

Rage.configure do
  config.deferred.enqueue_middleware.use MyCustomMiddleware
end

Returns:



803
804
805
# File 'lib/rage/configuration.rb', line 803

def enqueue_middleware
  @enqueue_middleware ||= Middleware.new
end

#perform_middlewareRage::Configuration::Deferred::Middleware

Configure perform middleware used by Rage::Deferred. See PerformMiddlewareInterface for details on the arguments passed to the middleware.

Examples:

Rage.configure do
  config.deferred.perform_middleware.use MyCustomMiddleware
end

Returns:



814
815
816
# File 'lib/rage/configuration.rb', line 814

def perform_middleware
  @perform_middleware ||= Middleware.new
end