hatchet-sdk 0.1.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +5 -1
  3. data/CHANGELOG.md +30 -0
  4. data/lib/hatchet/clients/grpc/admin.rb +45 -2
  5. data/lib/hatchet/clients/grpc/dispatcher.rb +33 -8
  6. data/lib/hatchet/condition_converter.rb +20 -12
  7. data/lib/hatchet/context.rb +6 -1
  8. data/lib/hatchet/contracts/dispatcher/dispatcher_pb.rb +3 -1
  9. data/lib/hatchet/contracts/dispatcher/dispatcher_services_pb.rb +1 -0
  10. data/lib/hatchet/contracts/v1/dispatcher_pb.rb +23 -1
  11. data/lib/hatchet/contracts/v1/dispatcher_services_pb.rb +2 -0
  12. data/lib/hatchet/contracts/v1/shared/condition_pb.rb +3 -1
  13. data/lib/hatchet/contracts/v1/shared/trigger_pb.rb +17 -0
  14. data/lib/hatchet/contracts/v1/workflows_pb.rb +4 -3
  15. data/lib/hatchet/contracts/v1/workflows_services_pb.rb +1 -0
  16. data/lib/hatchet/contracts/workflows/workflows_pb.rb +2 -4
  17. data/lib/hatchet/contracts/workflows/workflows_services_pb.rb +1 -1
  18. data/lib/hatchet/durable_context.rb +102 -33
  19. data/lib/hatchet/engine_version.rb +50 -0
  20. data/lib/hatchet/eviction_policy.rb +60 -0
  21. data/lib/hatchet/exceptions.rb +26 -0
  22. data/lib/hatchet/features/cron.rb +2 -1
  23. data/lib/hatchet/task.rb +7 -0
  24. data/lib/hatchet/version.rb +1 -1
  25. data/lib/hatchet/worker/durable_event_listener.rb +735 -0
  26. data/lib/hatchet/worker/durable_eviction/cache.rb +205 -0
  27. data/lib/hatchet/worker/durable_eviction/manager.rb +233 -0
  28. data/lib/hatchet/worker/runner.rb +279 -53
  29. data/lib/hatchet/worker_obj.rb +60 -4
  30. data/lib/hatchet/workflow.rb +8 -4
  31. data/lib/hatchet-sdk.rb +13 -3
  32. data/sig/hatchet/clients/grpc/dispatcher.rbs +2 -0
  33. data/sig/hatchet/durable_context.rbs +8 -2
  34. data/sig/hatchet/engine_version.rbs +12 -0
  35. data/sig/hatchet/eviction_policy.rbs +14 -0
  36. data/sig/hatchet/exceptions.rbs +12 -0
  37. data/sig/hatchet/task.rbs +2 -0
  38. data/sig/hatchet/worker/durable_event_listener.rbs +31 -0
  39. data/sig/hatchet/worker/durable_eviction/cache.rbs +41 -0
  40. data/sig/hatchet/worker/durable_eviction/manager.rbs +37 -0
  41. data/sig/hatchet/worker/runner.rbs +7 -1
  42. data/sig/hatchet/worker_obj.rbs +3 -0
  43. data/sig/hatchet/workflow.rbs +1 -1
  44. data/sig/hatchet-sdk.rbs +1 -1
  45. metadata +15 -4
@@ -1,7 +1,13 @@
1
1
  module Hatchet
2
2
  class DurableContext < Context
3
- def sleep_for: (duration: Integer | String) -> Hash[String, untyped]?
4
- def wait_for: (String key, untyped condition) -> Hash[String, untyped]
3
+ attr_accessor eviction_manager: WorkerRuntime::DurableEviction::DurableEvictionManager?
4
+ attr_accessor action_key: String?
5
+ attr_accessor durable_event_listener: WorkerRuntime::DurableEventListener?
6
+ attr_accessor invocation_count: Integer?
7
+ attr_accessor engine_version: String?
8
+
9
+ def sleep_for: (duration: Integer | String, ?label: String?) -> Hash[String, untyped]?
10
+ def wait_for: (String key, untyped condition, ?label: String?) -> Hash[String, untyped]
5
11
 
6
12
  private
7
13
 
@@ -0,0 +1,12 @@
1
+ module Hatchet
2
+ module MinEngineVersion
3
+ SLOT_CONFIG: String
4
+ DURABLE_EVICTION: String
5
+ OBSERVABILITY: String
6
+ end
7
+
8
+ module EngineVersion
9
+ def self.parse_semver: (String? version) -> [Integer, Integer, Integer]
10
+ def self.semver_less_than: (String? a, String? b) -> bool
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Hatchet
2
+ class EvictionPolicy
3
+ attr_reader ttl: Numeric?
4
+ attr_reader allow_capacity_eviction: bool
5
+ attr_reader priority: Integer
6
+
7
+ def initialize: (ttl: Numeric?, ?allow_capacity_eviction: bool, ?priority: Integer) -> void
8
+ def ==: (untyped other) -> bool
9
+ def eql?: (untyped other) -> bool
10
+ def hash: () -> Integer
11
+ end
12
+
13
+ DEFAULT_DURABLE_TASK_EVICTION_POLICY: EvictionPolicy
14
+ end
@@ -23,4 +23,16 @@ module Hatchet
23
23
 
24
24
  def initialize: (Array[TaskRunError] exceptions) -> void
25
25
  end
26
+
27
+ class NonDeterminismError < Error
28
+ attr_reader task_external_id: String?
29
+ attr_reader invocation_count: Integer?
30
+ attr_reader node_id: Integer?
31
+
32
+ def initialize: (String message, ?task_external_id: String?, ?invocation_count: Integer?, ?node_id: Integer?) -> void
33
+ end
34
+
35
+ class DurableTaskEvictedError < Error
36
+ def initialize: (?String message) -> void
37
+ end
26
38
  end
data/sig/hatchet/task.rbs CHANGED
@@ -13,6 +13,7 @@ module Hatchet
13
13
  attr_reader wait_for: Array[untyped]
14
14
  attr_reader skip_if: Array[untyped]
15
15
  attr_reader durable: bool
16
+ attr_reader eviction_policy: EvictionPolicy?
16
17
  attr_reader fn: Proc?
17
18
  attr_reader workflow: Workflow?
18
19
  attr_reader client: Client?
@@ -32,6 +33,7 @@ module Hatchet
32
33
  ?wait_for: Array[untyped],
33
34
  ?skip_if: Array[untyped],
34
35
  ?durable: bool,
36
+ ?eviction_policy: EvictionPolicy?,
35
37
  ?workflow: Workflow?,
36
38
  ?client: Client?,
37
39
  ?deps: Hash[Symbol, Proc]?
@@ -0,0 +1,31 @@
1
+ module Hatchet
2
+ module WorkerRuntime
3
+ class DurableEventListener
4
+ DEFAULT_RECONNECT_INTERVAL: Integer
5
+ EVICTION_ACK_TIMEOUT_SECONDS: Float
6
+
7
+ class WaitForEvent < Struct[untyped]
8
+ attr_accessor wait_for_conditions: untyped
9
+ attr_accessor label: String?
10
+ end
11
+
12
+ class MemoEvent < Struct[untyped]
13
+ attr_accessor memo_key: String
14
+ attr_accessor result: String?
15
+ end
16
+
17
+ attr_reader worker_id: String?
18
+
19
+ def initialize: (config: Config, channel: untyped, logger: Logger, ?on_server_evict: Proc?) -> void
20
+ def start: (String worker_id) -> void
21
+ def ensure_started: (String worker_id) -> void
22
+ def stop: () -> void
23
+ def send_event: (String durable_task_external_id, Integer invocation_count, (WaitForEvent | MemoEvent) event) -> untyped
24
+ def wait_for_callback: (String durable_task_external_id, Integer invocation_count, Integer branch_id, Integer node_id) -> Hash[Symbol, untyped]
25
+ def send_evict_invocation: (String durable_task_external_id, Integer invocation_count, ?reason: String?) -> void
26
+ def send_memo_completed_notification: (durable_task_external_id: String, node_id: Integer, branch_id: Integer, invocation_count: Integer, memo_key: String, memo_result_payload: String) -> void
27
+ def cleanup_task_state: (String durable_task_external_id, Integer invocation_count) -> void
28
+ def handle_response_for_test: (untyped response) -> void
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,41 @@
1
+ module Hatchet
2
+ module WorkerRuntime
3
+ module DurableEviction
4
+ module EvictionCause
5
+ TTL_EXCEEDED: Symbol
6
+ CAPACITY_PRESSURE: Symbol
7
+ WORKER_SHUTDOWN: Symbol
8
+ end
9
+
10
+ class DurableRunRecord
11
+ attr_reader key: String
12
+ attr_reader step_run_id: String
13
+ attr_reader invocation_count: Integer
14
+ attr_reader eviction_policy: EvictionPolicy?
15
+ attr_reader registered_at: Time
16
+ attr_accessor waiting_since: Time?
17
+ attr_accessor wait_kind: String?
18
+ attr_accessor wait_resource_id: String?
19
+ attr_accessor eviction_reason: String?
20
+ attr_accessor wait_count: Integer
21
+
22
+ def initialize: (key: String, step_run_id: String, invocation_count: Integer, eviction_policy: EvictionPolicy?, registered_at: Time) -> void
23
+ def waiting?: () -> bool
24
+ end
25
+
26
+ class DurableEvictionCache
27
+ def initialize: () -> void
28
+ def register_run: (String key, step_run_id: String, invocation_count: Integer, now: Time, eviction_policy: EvictionPolicy?) -> void
29
+ def unregister_run: (String key) -> void
30
+ def get: (String key) -> DurableRunRecord?
31
+ def all_waiting: () -> Array[DurableRunRecord]
32
+ def find_key_by_step_run_id: (String step_run_id) -> String?
33
+ def mark_waiting: (String key, now: Time, wait_kind: String, resource_id: String) -> void
34
+ def mark_active: (String key, now: Time) -> void
35
+ def select_eviction_candidate: (now: Time, durable_slots: Integer, reserve_slots: Integer, min_wait_for_capacity_eviction: Numeric) -> String?
36
+
37
+ def self.build_eviction_reason: (Symbol cause, DurableRunRecord rec, ?ttl: Numeric?) -> String
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,37 @@
1
+ module Hatchet
2
+ module WorkerRuntime
3
+ module DurableEviction
4
+ class DurableEvictionConfig
5
+ attr_reader check_interval: Float
6
+ attr_reader reserve_slots: Integer
7
+ attr_reader min_wait_for_capacity_eviction: Float
8
+
9
+ def initialize: (?check_interval: Float, ?reserve_slots: Integer, ?min_wait_for_capacity_eviction: Float) -> void
10
+ end
11
+
12
+ DEFAULT_DURABLE_EVICTION_CONFIG: DurableEvictionConfig
13
+
14
+ class DurableEvictionManager
15
+ attr_reader cache: DurableEvictionCache
16
+
17
+ def initialize: (
18
+ durable_slots: Integer,
19
+ cancel_local: Proc,
20
+ request_eviction_with_ack: Proc,
21
+ ?config: DurableEvictionConfig,
22
+ ?cache: DurableEvictionCache?,
23
+ ?logger: Logger?
24
+ ) -> void
25
+
26
+ def start: () -> void
27
+ def stop: () -> void
28
+ def register_run: (String key, step_run_id: String, invocation_count: Integer, eviction_policy: EvictionPolicy?) -> void
29
+ def unregister_run: (String key) -> void
30
+ def mark_waiting: (String key, wait_kind: String, resource_id: String) -> void
31
+ def mark_active: (String key) -> void
32
+ def handle_server_eviction: (String step_run_id, Integer invocation_count) -> void
33
+ def evict_all_waiting: () -> Integer
34
+ end
35
+ end
36
+ end
37
+ end
@@ -1,13 +1,19 @@
1
1
  module Hatchet
2
2
  module WorkerRuntime
3
3
  class Runner
4
+ attr_reader eviction_manager: DurableEviction::DurableEvictionManager?
5
+ attr_reader durable_event_listener: DurableEventListener?
6
+
4
7
  def initialize: (
5
8
  workflows: Array[Workflow | Task],
6
9
  slots: Integer,
7
10
  dispatcher_client: Clients::Grpc::Dispatcher,
8
11
  event_client: Clients::Grpc::EventClient,
9
12
  logger: Logger,
10
- client: Client
13
+ client: Client,
14
+ ?engine_version: String?,
15
+ ?durable_slots: Integer?,
16
+ ?worker_id: String?
11
17
  ) -> void
12
18
 
13
19
  def execute: (untyped action) -> void
@@ -6,12 +6,15 @@ module Hatchet
6
6
  attr_reader labels: Hash[String, String | Integer]
7
7
  attr_reader client: Client
8
8
  attr_accessor worker_id: String?
9
+ attr_reader durable_slots: Integer
10
+ attr_reader engine_version: String?
9
11
 
10
12
  def initialize: (
11
13
  name: String,
12
14
  client: Client,
13
15
  ?workflows: Array[Workflow | Task],
14
16
  ?slots: Integer,
17
+ ?durable_slots: Integer?,
15
18
  ?labels: Hash[String, String | Integer]
16
19
  ) -> void
17
20
 
@@ -27,7 +27,7 @@ module Hatchet
27
27
  ) -> void
28
28
 
29
29
  def task: (Symbol | String name, **untyped opts) { (Hash[String, untyped], Context) -> untyped } -> Task
30
- def durable_task: (Symbol | String name, **untyped opts) { (Hash[String, untyped], DurableContext) -> untyped } -> Task
30
+ def durable_task: (Symbol | String name, ?eviction_policy: EvictionPolicy?, **untyped opts) { (Hash[String, untyped], DurableContext) -> untyped } -> Task
31
31
  def on_failure_task: (**untyped opts) { (Hash[String, untyped], Context) -> untyped } -> Task
32
32
  def on_success_task: (**untyped opts) { (Hash[String, untyped], Context) -> untyped } -> Task
33
33
  def to_proto: (Config config) -> untyped
data/sig/hatchet-sdk.rbs CHANGED
@@ -40,7 +40,7 @@ module Hatchet
40
40
 
41
41
  def workflow: (name: String, **untyped opts) -> Workflow
42
42
  def task: (name: String, **untyped opts) { (Hash[String, untyped], Context) -> untyped } -> Task
43
- def durable_task: (name: String, **untyped opts) { (Hash[String, untyped], DurableContext) -> untyped } -> Task
43
+ def durable_task: (name: String, ?eviction_policy: EvictionPolicy?, **untyped opts) { (Hash[String, untyped], DurableContext) -> untyped } -> Task
44
44
  def worker: (String name, **untyped opts) -> Worker
45
45
 
46
46
  def logger: () -> Logger
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hatchet-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - gabriel ruttner
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-02-28 00:00:00.000000000 Z
11
+ date: 2026-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -142,14 +142,14 @@ dependencies:
142
142
  requirements:
143
143
  - - "~>"
144
144
  - !ruby/object:Gem::Version
145
- version: '3.0'
145
+ version: '3.13'
146
146
  type: :development
147
147
  prerelease: false
148
148
  version_requirements: !ruby/object:Gem::Requirement
149
149
  requirements:
150
150
  - - "~>"
151
151
  - !ruby/object:Gem::Version
152
- version: '3.0'
152
+ version: '3.13'
153
153
  description: The official Ruby SDK for Hatchet, a distributed, fault-tolerant task
154
154
  orchestration engine. Easily integrate Hatchet's task scheduling and workflow orchestration
155
155
  capabilities into your Ruby applications.
@@ -450,12 +450,15 @@ files:
450
450
  - lib/hatchet/contracts/v1/dispatcher_pb.rb
451
451
  - lib/hatchet/contracts/v1/dispatcher_services_pb.rb
452
452
  - lib/hatchet/contracts/v1/shared/condition_pb.rb
453
+ - lib/hatchet/contracts/v1/shared/trigger_pb.rb
453
454
  - lib/hatchet/contracts/v1/workflows_pb.rb
454
455
  - lib/hatchet/contracts/v1/workflows_services_pb.rb
455
456
  - lib/hatchet/contracts/workflows/workflows_pb.rb
456
457
  - lib/hatchet/contracts/workflows/workflows_services_pb.rb
457
458
  - lib/hatchet/default_filter.rb
458
459
  - lib/hatchet/durable_context.rb
460
+ - lib/hatchet/engine_version.rb
461
+ - lib/hatchet/eviction_policy.rb
459
462
  - lib/hatchet/exceptions.rb
460
463
  - lib/hatchet/features/cel.rb
461
464
  - lib/hatchet/features/cron.rb
@@ -475,6 +478,9 @@ files:
475
478
  - lib/hatchet/trigger_options.rb
476
479
  - lib/hatchet/version.rb
477
480
  - lib/hatchet/worker/action_listener.rb
481
+ - lib/hatchet/worker/durable_event_listener.rb
482
+ - lib/hatchet/worker/durable_eviction/cache.rb
483
+ - lib/hatchet/worker/durable_eviction/manager.rb
478
484
  - lib/hatchet/worker/health_check.rb
479
485
  - lib/hatchet/worker/runner.rb
480
486
  - lib/hatchet/worker/workflow_run_listener.rb
@@ -498,6 +504,8 @@ files:
498
504
  - sig/hatchet/context_vars.rbs
499
505
  - sig/hatchet/default_filter.rbs
500
506
  - sig/hatchet/durable_context.rbs
507
+ - sig/hatchet/engine_version.rbs
508
+ - sig/hatchet/eviction_policy.rbs
501
509
  - sig/hatchet/exceptions.rbs
502
510
  - sig/hatchet/features/cel.rbs
503
511
  - sig/hatchet/features/cron.rbs
@@ -517,6 +525,9 @@ files:
517
525
  - sig/hatchet/trigger_options.rbs
518
526
  - sig/hatchet/version.rbs
519
527
  - sig/hatchet/worker/action_listener.rbs
528
+ - sig/hatchet/worker/durable_event_listener.rbs
529
+ - sig/hatchet/worker/durable_eviction/cache.rbs
530
+ - sig/hatchet/worker/durable_eviction/manager.rbs
520
531
  - sig/hatchet/worker/health_check.rbs
521
532
  - sig/hatchet/worker/runner.rbs
522
533
  - sig/hatchet/worker/workflow_run_listener.rbs