Class: JobWorkflow::TaskThrottle

Inherits:
Object
  • Object
show all
Defined in:
lib/job_workflow/task_throttle.rb,
sig/generated/job_workflow/task_throttle.rbs

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key:, limit: nil, ttl: 180) ⇒ TaskThrottle

: (key: String, ?limit: Integer?, ?ttl: Integer) -> void

Parameters:

  • key: (String)
  • limit: (Integer, nil) (defaults to: nil)
  • ttl: (Integer) (defaults to: 180)


28
29
30
31
32
# File 'lib/job_workflow/task_throttle.rb', line 28

def initialize(key:, limit: nil, ttl: 180)
  @key = key
  @limit = limit
  @ttl = ttl
end

Instance Attribute Details

#keyString (readonly)

Signature:

  • String

Returns:

  • (String)


5
6
7
# File 'lib/job_workflow/task_throttle.rb', line 5

def key
  @key
end

#limitInteger? (readonly)

Signature:

  • Integer?

Returns:

  • (Integer, nil)


6
7
8
# File 'lib/job_workflow/task_throttle.rb', line 6

def limit
  @limit
end

#ttlInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


7
8
9
# File 'lib/job_workflow/task_throttle.rb', line 7

def ttl
  @ttl
end

Class Method Details

.from_primitive_value_with_task(value:, task:) ⇒ TaskThrottle

: (value: Integer | Hash[Symbol, untyped], task: Task) -> TaskThrottle

Parameters:

  • value: (Integer, Hash[Symbol, untyped])
  • task: (Task)

Returns:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/job_workflow/task_throttle.rb', line 11

def from_primitive_value_with_task(value:, task:)
  case value
  when Integer
    new(key: task.throttle_prefix_key, limit: value)
  when Hash
    new(
      key: value[:key] || task.throttle_prefix_key,
      limit: value[:limit],
      ttl: value[:ttl] || 180
    )
  else
    raise ArgumentError, "throttle must be Integer or Hash"
  end
end

Instance Method Details

#semaphoreSemaphore?

: () -> Semaphore?

Returns:



35
36
37
38
39
40
41
42
43
44
# File 'lib/job_workflow/task_throttle.rb', line 35

def semaphore
  local_limit = limit
  return if local_limit.nil?

  Semaphore.new(
    concurrency_key: key,
    concurrency_duration: ttl.seconds,
    concurrency_limit: local_limit
  )
end