Class: Async::Background::Web::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/async/background/web/configuration.rb

Constant Summary collapse

DEFAULT_LIST_LIMIT =
50
MAX_LIST_LIMIT =
200
DEFAULT_COUNTS_TTL =
3.0
DEFAULT_POLL_INTERVAL_MS =
2000
DEFAULT_STREAM_POLL_SECONDS =
0.5
DEFAULT_STREAM_HEARTBEAT_SECONDS =
25.0
DEFAULT_STREAM_RETRY_MS =
5000
TRANSPORTS =
%i[polling sse].freeze
DEFAULT_TRANSPORT =
:sse
DEFAULT_REDACT =
->(args) { args.is_a?(Array) ? args.map { '***' } : args }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/async/background/web/configuration.rb', line 37

def initialize
  @queue_path = Queue::Store.default_path
  @auth = nil
  @expose_args = false
  @redact_args = DEFAULT_REDACT
  @metrics_path = nil
  @total_workers = nil
  @counts_cache_ttl = DEFAULT_COUNTS_TTL
  @list_limit = DEFAULT_LIST_LIMIT
  @poll_interval_ms = DEFAULT_POLL_INTERVAL_MS
  @transport = DEFAULT_TRANSPORT
  @stream_poll_seconds = DEFAULT_STREAM_POLL_SECONDS
  @stream_heartbeat_seconds = DEFAULT_STREAM_HEARTBEAT_SECONDS
  @stream_retry_ms = DEFAULT_STREAM_RETRY_MS
  @title = 'Async::Background'
  @mount_path = ''
  @logger = nil
end

Instance Attribute Details

#authObject

Returns the value of attribute auth.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def auth
  @auth
end

#counts_cache_ttlObject

Returns the value of attribute counts_cache_ttl.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def counts_cache_ttl
  @counts_cache_ttl
end

#expose_argsObject

Returns the value of attribute expose_args.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def expose_args
  @expose_args
end

#list_limitObject

Returns the value of attribute list_limit.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def list_limit
  @list_limit
end

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def logger
  @logger
end

#metrics_pathObject

Returns the value of attribute metrics_path.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def metrics_path
  @metrics_path
end

#mount_pathObject

Returns the value of attribute mount_path.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def mount_path
  @mount_path
end

#poll_interval_msObject

Returns the value of attribute poll_interval_ms.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def poll_interval_ms
  @poll_interval_ms
end

#queue_pathObject

Returns the value of attribute queue_path.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def queue_path
  @queue_path
end

#redact_argsObject

Returns the value of attribute redact_args.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def redact_args
  @redact_args
end

#stream_heartbeat_secondsObject

Returns the value of attribute stream_heartbeat_seconds.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def stream_heartbeat_seconds
  @stream_heartbeat_seconds
end

#stream_poll_secondsObject

Returns the value of attribute stream_poll_seconds.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def stream_poll_seconds
  @stream_poll_seconds
end

#stream_retry_msObject

Returns the value of attribute stream_retry_ms.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def stream_retry_ms
  @stream_retry_ms
end

#titleObject

Returns the value of attribute title.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def title
  @title
end

#total_workersObject

Returns the value of attribute total_workers.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def total_workers
  @total_workers
end

#transportObject

Returns the value of attribute transport.



20
21
22
# File 'lib/async/background/web/configuration.rb', line 20

def transport
  @transport
end

Instance Method Details

#limit_for(requested) ⇒ Object

Strict request-path parsing. Silently changing a malformed requested page size to the default makes API clients repeat or skip work.



73
74
75
76
77
78
79
80
81
82
# File 'lib/async/background/web/configuration.rb', line 73

def limit_for(requested)
  return list_limit if requested.nil? || requested.empty?

  value = Integer(requested, 10)
  raise RequestError, 'limit must be a positive integer' unless value.positive?

  [value, MAX_LIST_LIMIT].min
rescue ArgumentError, TypeError
  raise RequestError, 'limit must be a positive integer'
end

#metrics_enabled?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/async/background/web/configuration.rb', line 84

def metrics_enabled?
  !metrics_path.nil?
end

#validate!Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/async/background/web/configuration.rb', line 56

def validate!
  validate_queue_path!
  validate_auth!
  validate_list_limit!
  validate_cache_ttl!
  validate_poll_interval!
  validate_transport!
  validate_stream!
  validate_redactor!
  validate_metrics!
  validate_mount_path!
  validate_logger!
  self
end