Class: Hatchet::EvictionPolicy

Inherits:
Object
  • Object
show all
Defined in:
lib/hatchet/eviction_policy.rb

Overview

Task-scoped eviction parameters for durable tasks.

Setting the durable task’s eviction policy to “nil“ means the task run is never eligible for eviction.

Examples:

Hatchet::EvictionPolicy.new(
  ttl: 600,                     # 10 minutes, in seconds
  allow_capacity_eviction: true,
  priority: 0,
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ttl:, allow_capacity_eviction: true, priority: 0) ⇒ EvictionPolicy

Returns a new instance of EvictionPolicy.

Parameters:

  • ttl (Numeric, nil)

    TTL in seconds (or nil to disable TTL-based eviction)

  • allow_capacity_eviction (Boolean) (defaults to: true)
  • priority (Integer) (defaults to: 0)


31
32
33
34
35
36
# File 'lib/hatchet/eviction_policy.rb', line 31

def initialize(ttl:, allow_capacity_eviction: true, priority: 0)
  @ttl = ttl
  @allow_capacity_eviction = allow_capacity_eviction
  @priority = priority
  freeze
end

Instance Attribute Details

#allow_capacity_evictionBoolean (readonly)

Returns Whether this task may be evicted under durable-slot pressure.

Returns:

  • (Boolean)

    Whether this task may be evicted under durable-slot pressure.



23
24
25
# File 'lib/hatchet/eviction_policy.rb', line 23

def allow_capacity_eviction
  @allow_capacity_eviction
end

#priorityInteger (readonly)

Returns Lower values are evicted first when multiple candidates exist.

Returns:

  • (Integer)

    Lower values are evicted first when multiple candidates exist.



26
27
28
# File 'lib/hatchet/eviction_policy.rb', line 26

def priority
  @priority
end

#ttlNumeric? (readonly)

Returns Maximum continuous waiting duration in seconds before TTL-eligible eviction. Applies to time spent in SDK-instrumented “waiting” states (e.g. :meth:‘DurableContext#sleep_for`, :meth:`DurableContext#wait_for`). “nil“ disables TTL eviction.

Returns:

  • (Numeric, nil)

    Maximum continuous waiting duration in seconds before TTL-eligible eviction. Applies to time spent in SDK-instrumented “waiting” states (e.g. :meth:‘DurableContext#sleep_for`, :meth:`DurableContext#wait_for`). “nil“ disables TTL eviction.



20
21
22
# File 'lib/hatchet/eviction_policy.rb', line 20

def ttl
  @ttl
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



38
39
40
41
42
43
# File 'lib/hatchet/eviction_policy.rb', line 38

def ==(other)
  other.is_a?(EvictionPolicy) &&
    other.ttl == ttl &&
    other.allow_capacity_eviction == allow_capacity_eviction &&
    other.priority == priority
end

#hashObject



46
47
48
# File 'lib/hatchet/eviction_policy.rb', line 46

def hash
  [self.class, ttl, allow_capacity_eviction, priority].hash
end