Class: JobContracts::DurationContract
- Defined in:
- lib/job_contracts/contracts/duration_contract.rb
Instance Attribute Summary
Attributes inherited from Contract
Instance Method Summary collapse
- #enforce!(contractable) ⇒ Object
-
#initialize(max:, queues: ["*"]) ⇒ DurationContract
constructor
A new instance of DurationContract.
Methods inherited from Contract
#actual, #after?, #before?, #breached?, #expected, #halt?, #satisfied?, #should_enforce?, #to_h
Constructor Details
#initialize(max:, queues: ["*"]) ⇒ DurationContract
Returns a new instance of DurationContract.
7 8 9 |
# File 'lib/job_contracts/contracts/duration_contract.rb', line 7 def initialize(max:, queues: ["*"]) super queues: queues, expected: {max: max} end |
Instance Method Details
#enforce!(contractable) ⇒ Object
11 12 13 14 15 |
# File 'lib/job_contracts/contracts/duration_contract.rb', line 11 def enforce!(contractable) actual[:duration] = (Time.current - Time.parse(contractable.enqueued_at)).seconds self.satisfied = actual[:duration] < expected[:max].seconds super end |