hatchet-sdk 0.6.0 → 0.7.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/lib/hatchet/clients/rest/.openapi-generator/FILES +9 -0
  4. data/lib/hatchet/clients/rest/README.md +16 -3
  5. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/filter_api.rb +4 -0
  6. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/operator_api.rb +405 -0
  7. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/api/webhook_api.rb +2 -0
  8. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/api_meta.rb +14 -4
  9. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/create_tenant_invite_request.rb +14 -4
  10. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/pause_workflow_request.rb +105 -0
  11. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/pause_workflow_request_pause.rb +343 -0
  12. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/pause_workflow_request_unpause.rb +262 -0
  13. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/tenant_invite.rb +11 -1
  14. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/tenant_member.rb +11 -1
  15. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/tenant_member_role.rb +2 -1
  16. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/update_tenant_invite_request.rb +14 -4
  17. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/update_tenant_member_request.rb +14 -4
  18. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_create_http_operator_request.rb +346 -0
  19. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_event.rb +14 -4
  20. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_http_operator.rb +372 -0
  21. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_http_operator_list.rb +231 -0
  22. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_task_summary.rb +14 -4
  23. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_update_http_operator_request.rb +252 -0
  24. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/v1_workflow_run.rb +14 -4
  25. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/workflow.rb +43 -1
  26. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/workflow_pause_scheduled_cron_run_queue_behavior.rb +40 -0
  27. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest/models/workflow_update_request.rb +7 -8
  28. data/lib/hatchet/clients/rest/lib/hatchet-sdk-rest.rb +9 -0
  29. data/lib/hatchet/concurrency.rb +5 -1
  30. data/lib/hatchet/context.rb +5 -2
  31. data/lib/hatchet/contracts/v1/workflows_pb.rb +1 -1
  32. data/lib/hatchet/durable_context.rb +5 -12
  33. data/lib/hatchet/features/cel.rb +2 -2
  34. data/lib/hatchet/features/cron.rb +5 -5
  35. data/lib/hatchet/features/events.rb +7 -7
  36. data/lib/hatchet/features/filters.rb +7 -7
  37. data/lib/hatchet/features/logs.rb +2 -2
  38. data/lib/hatchet/features/metrics.rb +6 -6
  39. data/lib/hatchet/features/rate_limits.rb +2 -2
  40. data/lib/hatchet/features/runs.rb +4 -5
  41. data/lib/hatchet/features/scheduled.rb +7 -7
  42. data/lib/hatchet/features/tenant.rb +2 -2
  43. data/lib/hatchet/features/workers.rb +5 -5
  44. data/lib/hatchet/features/workflows.rb +6 -6
  45. data/lib/hatchet/version.rb +1 -1
  46. data/lib/hatchet/workflow.rb +58 -33
  47. data/lib/hatchet-sdk.rb +65 -32
  48. metadata +11 -2
@@ -5,14 +5,12 @@ require "securerandom"
5
5
 
6
6
  module Hatchet
7
7
  # Extended context for durable tasks that supports sleep and event-waiting
8
- # across task suspensions.
8
+ # across task suspensions. All methods and attributes of {Context} are also
9
+ # available.
9
10
  #
10
11
  # Durable tasks can be suspended and resumed by the Hatchet engine,
11
12
  # allowing long-running workflows that survive process restarts.
12
13
  #
13
- # Uses V1::V1Dispatcher for registering and listening for durable events
14
- # via bidirectional gRPC streaming.
15
- #
16
14
  # @example Sleep for a duration
17
15
  # hatchet.durable_task(name: "my_task") do |input, ctx|
18
16
  # ctx.sleep_for(duration: 60) # sleep for 60 seconds
@@ -42,10 +40,8 @@ module Hatchet
42
40
  attr_accessor :engine_version
43
41
 
44
42
  # Sleep for a specified duration. The task is suspended and resumed
45
- # by the engine after the duration expires.
46
- #
47
- # Delegates to {#wait_for} with a {Hatchet::SleepCondition} so that both
48
- # sleeps and event waits share a single registration / eviction path.
43
+ # by the engine after the duration expires, so no worker slot is blocked
44
+ # while sleeping (subject to the task's eviction policy).
49
45
  #
50
46
  # @param duration [Integer, String] Duration in seconds, or a duration string (e.g. "60s")
51
47
  # @param label [String, nil] Optional wait label shown in durable event logs.
@@ -62,11 +58,8 @@ module Hatchet
62
58
  # Wait for a condition to be met (event or sleep).
63
59
  # The task is suspended and resumed when the condition is satisfied.
64
60
  #
65
- # Register the durable wait with ``send_event`` first, then start eviction
66
- # tracking only while blocked on ``wait_for_callback``.
67
- #
68
61
  # @param key [String] A unique key for this wait operation
69
- # @param condition [Object] The condition to wait for (UserEventCondition, SleepCondition, Hash, etc.)
62
+ # @param condition [UserEventCondition, SleepCondition, OrCondition] The condition to wait for
70
63
  # @param label [String, nil] Optional wait label shown in durable event logs.
71
64
  # @return [Hash] Result from the wait, including which condition was satisfied
72
65
  def wait_for(key, condition, label: nil)
@@ -23,7 +23,7 @@ module Hatchet
23
23
  # CEL (Common Expression Language) expressions used in filters and conditions.
24
24
  #
25
25
  # @example Debugging a CEL expression
26
- # result = cel_client.debug(
26
+ # result = hatchet.cel.debug(
27
27
  # expression: 'input.value > 10',
28
28
  # input: { value: 15 }
29
29
  # )
@@ -59,7 +59,7 @@ module Hatchet
59
59
  # @raise [RuntimeError] If no response is received from the CEL debug API
60
60
  # @raise [HatchetSdkRest::ApiError] If the API request fails
61
61
  # @example
62
- # result = cel_client.debug(
62
+ # result = hatchet.cel.debug(
63
63
  # expression: 'input.count > 5 && metadata.env == "prod"',
64
64
  # input: { count: 10 },
65
65
  # additional_metadata: { env: 'prod' }
@@ -8,7 +8,7 @@ module Hatchet
8
8
  # listing, and retrieving cron workflow triggers.
9
9
  #
10
10
  # @example Creating a cron trigger
11
- # cron = cron_client.create(
11
+ # cron = hatchet.cron.create(
12
12
  # workflow_name: "my-workflow",
13
13
  # cron_name: "daily-run",
14
14
  # expression: "0 0 * * *",
@@ -45,7 +45,7 @@ module Hatchet
45
45
  # @raise [ArgumentError] If the cron expression is invalid
46
46
  # @raise [HatchetSdkRest::ApiError] If the API request fails
47
47
  # @example
48
- # cron = cron_client.create(
48
+ # cron = hatchet.cron.create(
49
49
  # workflow_name: "my-workflow",
50
50
  # cron_name: "hourly-run",
51
51
  # expression: "0 * * * *",
@@ -76,7 +76,7 @@ module Hatchet
76
76
  # @return [void]
77
77
  # @raise [HatchetSdkRest::ApiError] If the API request fails
78
78
  # @example
79
- # cron_client.delete("cron-123")
79
+ # hatchet.cron.delete("cron-123")
80
80
  def delete(cron_id)
81
81
  @workflow_api.workflow_cron_delete(@config.tenant_id, cron_id.to_s)
82
82
  end
@@ -94,7 +94,7 @@ module Hatchet
94
94
  # @return [Object] A list of cron workflows
95
95
  # @raise [HatchetSdkRest::ApiError] If the API request fails
96
96
  # @example
97
- # crons = cron_client.list(limit: 10, workflow_name: "my-workflow")
97
+ # crons = hatchet.cron.list(limit: 10, workflow_name: "my-workflow")
98
98
  def list(offset: nil, limit: nil, workflow_id: nil, additional_metadata: nil,
99
99
  order_by_field: nil, order_by_direction: nil, workflow_name: nil, cron_name: nil)
100
100
  @workflow_api.cron_workflow_list(
@@ -118,7 +118,7 @@ module Hatchet
118
118
  # @return [Object] The requested cron workflow instance
119
119
  # @raise [HatchetSdkRest::ApiError] If the API request fails
120
120
  # @example
121
- # cron = cron_client.get("cron-123")
121
+ # cron = hatchet.cron.get("cron-123")
122
122
  def get(cron_id)
123
123
  @workflow_api.workflow_cron_get(@config.tenant_id, cron_id.to_s)
124
124
  end
@@ -11,9 +11,9 @@ module Hatchet
11
11
  # the REST API for read operations (list, get, etc.).
12
12
  #
13
13
  # @example Creating an event
14
- # response = events.push(
15
- # key: "user-login",
16
- # data: { user_id: 123, action: "login" },
14
+ # response = hatchet.events.push(
15
+ # "user-login",
16
+ # { user_id: 123, action: "login" },
17
17
  # additional_metadata: { ip_address: "192.168.1.1" }
18
18
  # )
19
19
  #
@@ -53,7 +53,7 @@ module Hatchet
53
53
  # @raise [ArgumentError] If required parameters are missing
54
54
  # @raise [Hatchet::Error] If the API request fails or returns an error
55
55
  # @example Creating a simple event
56
- # response = events.create(
56
+ # response = hatchet.events.create(
57
57
  # key: "user-login",
58
58
  # data: { user_id: 123, action: "login" },
59
59
  # additional_metadata: { ip_address: "192.168.1.1" }
@@ -80,7 +80,7 @@ module Hatchet
80
80
  # @return [Object] The gRPC response containing the created event details
81
81
  # @raise [Hatchet::Error] If the API request fails or returns an error
82
82
  # @example Push a simple event
83
- # response = events.push(
83
+ # response = hatchet.events.push(
84
84
  # "user-signup",
85
85
  # { user_id: 456, email: "user@example.com" },
86
86
  # additional_metadata: { source: "web" }
@@ -106,7 +106,7 @@ module Hatchet
106
106
  # { key: "user-signup", data: { user_id: 1 } },
107
107
  # { key: "user-login", data: { user_id: 1 }, priority: 1 }
108
108
  # ]
109
- # response = events.bulk_push(events_data)
109
+ # response = hatchet.events.bulk_push(events_data)
110
110
  def bulk_push(events, namespace: nil)
111
111
  grpc_events = events.map do |event|
112
112
  {
@@ -135,7 +135,7 @@ module Hatchet
135
135
  # @return [HatchetSdkRest::V1EventList] List of events matching the filters
136
136
  # @raise [Hatchet::Error] If the API request fails or returns an error
137
137
  # @example List recent events
138
- # events = events_client.list(
138
+ # events = hatchet.events.list(
139
139
  # limit: 10,
140
140
  # since: Time.now - 24 * 60 * 60,
141
141
  # keys: ["user-signup", "user-login"]
@@ -8,10 +8,10 @@ module Hatchet
8
8
  # listing, updating, and deleting filters in the Hatchet system.
9
9
  #
10
10
  # @example Listing filters
11
- # filters = filters_client.list(limit: 10, workflow_ids: ["wf-1"])
11
+ # filters = hatchet.filters.list(limit: 10, workflow_ids: ["wf-1"])
12
12
  #
13
13
  # @example Creating a filter
14
- # filter = filters_client.create(
14
+ # filter = hatchet.filters.create(
15
15
  # workflow_id: "wf-1",
16
16
  # expression: 'input.priority > 5',
17
17
  # scope: "high-priority"
@@ -40,7 +40,7 @@ module Hatchet
40
40
  # @return [Object] A list of filters matching the specified criteria
41
41
  # @raise [HatchetSdkRest::ApiError] If the API request fails
42
42
  # @example
43
- # filters = filters_client.list(limit: 10, workflow_ids: ["wf-1"])
43
+ # filters = hatchet.filters.list(limit: 10, workflow_ids: ["wf-1"])
44
44
  def list(limit: nil, offset: nil, workflow_ids: nil, scopes: nil)
45
45
  @filter_api.v1_filter_list(
46
46
  @config.tenant_id,
@@ -59,7 +59,7 @@ module Hatchet
59
59
  # @return [Object] The filter details
60
60
  # @raise [HatchetSdkRest::ApiError] If the API request fails
61
61
  # @example
62
- # filter = filters_client.get("filter-123")
62
+ # filter = hatchet.filters.get("filter-123")
63
63
  def get(filter_id)
64
64
  @filter_api.v1_filter_get(@config.tenant_id, filter_id)
65
65
  end
@@ -73,7 +73,7 @@ module Hatchet
73
73
  # @return [Object] The created filter
74
74
  # @raise [HatchetSdkRest::ApiError] If the API request fails
75
75
  # @example
76
- # filter = filters_client.create(
76
+ # filter = hatchet.filters.create(
77
77
  # workflow_id: "wf-1",
78
78
  # expression: 'input.value > 10',
79
79
  # scope: "my-scope",
@@ -95,7 +95,7 @@ module Hatchet
95
95
  # @return [Object] The deleted filter
96
96
  # @raise [HatchetSdkRest::ApiError] If the API request fails
97
97
  # @example
98
- # filters_client.delete("filter-123")
98
+ # hatchet.filters.delete("filter-123")
99
99
  def delete(filter_id)
100
100
  @filter_api.v1_filter_delete(@config.tenant_id, filter_id)
101
101
  end
@@ -107,7 +107,7 @@ module Hatchet
107
107
  # @return [Object] The updated filter
108
108
  # @raise [HatchetSdkRest::ApiError] If the API request fails
109
109
  # @example
110
- # filters_client.update("filter-123", { expression: 'input.value > 20' })
110
+ # hatchet.filters.update("filter-123", { expression: 'input.value > 20' })
111
111
  def update(filter_id, updates)
112
112
  update_request = HatchetSdkRest::V1UpdateFilterRequest.new(updates)
113
113
  @filter_api.v1_filter_update(@config.tenant_id, filter_id, update_request)
@@ -10,7 +10,7 @@ module Hatchet
10
10
  # associated with task runs in the Hatchet system.
11
11
  #
12
12
  # @example Listing logs for a task run
13
- # logs = logs_client.list("task-run-id", limit: 100)
13
+ # logs = hatchet.logs.list("task-run-id", limit: 100)
14
14
  #
15
15
  # @since 0.1.0
16
16
  class Logs
@@ -35,7 +35,7 @@ module Hatchet
35
35
  # @return [Object] A list of log lines for the specified task run
36
36
  # @raise [HatchetSdkRest::ApiError] If the API request fails
37
37
  # @example
38
- # logs = logs_client.list("task-run-123", limit: 500, since: Time.now - 3600)
38
+ # logs = hatchet.logs.list("task-run-123", limit: 500, since: Time.now - 3600)
39
39
  def list(task_run_id, limit: 1000, since: nil, until_time: nil)
40
40
  @log_api.v1_log_line_list(
41
41
  task_run_id,
@@ -13,10 +13,10 @@ module Hatchet
13
13
  # Prometheus metrics, task statistics, and task metrics from the Hatchet system.
14
14
  #
15
15
  # @example Getting queue metrics
16
- # metrics = metrics_client.get_queue_metrics
16
+ # metrics = hatchet.metrics.get_queue_metrics
17
17
  #
18
18
  # @example Getting task metrics
19
- # task_metrics = metrics_client.get_task_metrics(
19
+ # task_metrics = hatchet.metrics.get_task_metrics(
20
20
  # since: Time.now - 86400,
21
21
  # workflow_ids: ["wf-1"]
22
22
  # )
@@ -41,7 +41,7 @@ module Hatchet
41
41
  # @return [Hash] The current queue metrics
42
42
  # @raise [HatchetSdkRest::ApiError] If the API request fails
43
43
  # @example
44
- # queues = metrics_client.get_queue_metrics
44
+ # queues = hatchet.metrics.get_queue_metrics
45
45
  def get_queue_metrics
46
46
  result = @tenant_api.tenant_get_step_run_queue_metrics(@config.tenant_id)
47
47
  result.queues || {}
@@ -52,7 +52,7 @@ module Hatchet
52
52
  # @return [String] The metrics in Prometheus text format
53
53
  # @raise [HatchetSdkRest::ApiError] If the API request fails
54
54
  # @example
55
- # prometheus_text = metrics_client.scrape_tenant_prometheus_metrics
55
+ # prometheus_text = hatchet.metrics.scrape_tenant_prometheus_metrics
56
56
  def scrape_tenant_prometheus_metrics
57
57
  @tenant_api.tenant_get_prometheus_metrics(@config.tenant_id)
58
58
  end
@@ -62,7 +62,7 @@ module Hatchet
62
62
  # @return [Object] The task statistics
63
63
  # @raise [HatchetSdkRest::ApiError] If the API request fails
64
64
  # @example
65
- # stats = metrics_client.get_task_stats
65
+ # stats = hatchet.metrics.get_task_stats
66
66
  def get_task_stats
67
67
  @tenant_api.tenant_get_task_stats(@config.tenant_id)
68
68
  end
@@ -77,7 +77,7 @@ module Hatchet
77
77
  # @return [TaskMetrics] Task metrics with counts per status
78
78
  # @raise [HatchetSdkRest::ApiError] If the API request fails
79
79
  # @example
80
- # metrics = metrics_client.get_task_metrics(
80
+ # metrics = hatchet.metrics.get_task_metrics(
81
81
  # since: Time.now - 86400,
82
82
  # workflow_ids: ["wf-1"]
83
83
  # )
@@ -8,7 +8,7 @@ module Hatchet
8
8
  # rate limits using the gRPC Admin client.
9
9
  #
10
10
  # @example Setting a rate limit
11
- # rate_limits_client.put(key: "api-calls", limit: 100, duration: :SECOND)
11
+ # hatchet.rate_limits.put(key: "api-calls", limit: 100, duration: :SECOND)
12
12
  #
13
13
  # @since 0.1.0
14
14
  class RateLimits
@@ -31,7 +31,7 @@ module Hatchet
31
31
  # @return [void]
32
32
  # @raise [GRPC::BadStatus] If the gRPC request fails
33
33
  # @example
34
- # rate_limits_client.put(key: "api-calls", limit: 100, duration: :SECOND)
34
+ # hatchet.rate_limits.put(key: "api-calls", limit: 100, duration: :SECOND)
35
35
  def put(key:, limit:, duration: :SECOND)
36
36
  @admin_grpc.put_rate_limit(key: key, limit: limit, duration: duration)
37
37
  end
@@ -72,8 +72,7 @@ module Hatchet
72
72
  # convenient Ruby interface.
73
73
  #
74
74
  # @example Creating a workflow run
75
- # runs = Features::Runs.new(rest_client, config)
76
- # response = runs.create(
75
+ # response = hatchet.runs.create(
77
76
  # name: "my-workflow",
78
77
  # input: { key: "value" },
79
78
  # additional_metadata: { source: "api" }
@@ -289,7 +288,7 @@ module Hatchet
289
288
  # @raise [ArgumentError] If the workflow_name or input parameters are nil or invalid
290
289
  # @raise [Hatchet::Error] If the API request fails or returns an error
291
290
  # @example Creating a workflow run
292
- # response = runs.create(
291
+ # response = hatchet.runs.create(
293
292
  # name: "simple-workflow",
294
293
  # input: { user_id: 123, action: "process_data" },
295
294
  # additional_metadata: { source: "api", priority: "high" }
@@ -446,9 +445,9 @@ module Hatchet
446
445
  # @raise [Timeout::Error] If the timeout is reached before completion
447
446
  # @raise [Hatchet::Error] If the API request fails or returns an error
448
447
  # @example Poll with default settings (1s interval, no timeout)
449
- # result = runs.poll("workflow-run-123")
448
+ # result = hatchet.runs.poll("workflow-run-123")
450
449
  # @example Poll with custom interval and timeout
451
- # result = runs.poll("workflow-run-123", interval: 2.0, timeout: 30.0)
450
+ # result = hatchet.runs.poll("workflow-run-123", interval: 2.0, timeout: 30.0)
452
451
  # @since 0.1.0
453
452
  def poll(workflow_run_id, interval: 1.0, timeout: nil)
454
453
  start_time = Time.now
@@ -10,7 +10,7 @@ module Hatchet
10
10
  # updating, bulk operations, listing, and retrieving scheduled workflow runs.
11
11
  #
12
12
  # @example Creating a scheduled workflow
13
- # scheduled = scheduled_client.create(
13
+ # scheduled = hatchet.scheduled.create(
14
14
  # workflow_name: "my-workflow",
15
15
  # trigger_at: Time.now + 3600,
16
16
  # input: { key: "value" },
@@ -44,7 +44,7 @@ module Hatchet
44
44
  # @return [Object] The created scheduled workflow instance
45
45
  # @raise [HatchetSdkRest::ApiError] If the API request fails
46
46
  # @example
47
- # scheduled = scheduled_client.create(
47
+ # scheduled = hatchet.scheduled.create(
48
48
  # workflow_name: "my-workflow",
49
49
  # trigger_at: Time.now + 3600,
50
50
  # input: { key: "value" },
@@ -70,7 +70,7 @@ module Hatchet
70
70
  # @return [void]
71
71
  # @raise [HatchetSdkRest::ApiError] If the API request fails
72
72
  # @example
73
- # scheduled_client.delete("scheduled-123")
73
+ # hatchet.scheduled.delete("scheduled-123")
74
74
  def delete(scheduled_id)
75
75
  @workflow_api.workflow_scheduled_delete(@config.tenant_id, scheduled_id)
76
76
  end
@@ -85,7 +85,7 @@ module Hatchet
85
85
  # @return [Object] The updated scheduled workflow instance
86
86
  # @raise [HatchetSdkRest::ApiError] If the API request fails
87
87
  # @example
88
- # scheduled_client.update("scheduled-123", trigger_at: Time.now + 7200)
88
+ # hatchet.scheduled.update("scheduled-123", trigger_at: Time.now + 7200)
89
89
  def update(scheduled_id, trigger_at:)
90
90
  request = HatchetSdkRest::UpdateScheduledWorkflowRunRequest.new(
91
91
  trigger_at: trigger_at.utc.iso8601,
@@ -139,7 +139,7 @@ module Hatchet
139
139
  # @return [Object] The bulk update response containing updated IDs and per-item errors
140
140
  # @raise [HatchetSdkRest::ApiError] If the API request fails
141
141
  # @example
142
- # scheduled_client.bulk_update([
142
+ # hatchet.scheduled.bulk_update([
143
143
  # { id: "scheduled-1", trigger_at: Time.now + 3600 },
144
144
  # { id: "scheduled-2", trigger_at: Time.now + 7200 }
145
145
  # ])
@@ -171,7 +171,7 @@ module Hatchet
171
171
  # @return [Object] A list of scheduled workflows matching the provided filters
172
172
  # @raise [HatchetSdkRest::ApiError] If the API request fails
173
173
  # @example
174
- # scheduled = scheduled_client.list(limit: 10, workflow_id: "wf-1")
174
+ # scheduled = hatchet.scheduled.list(limit: 10, workflow_id: "wf-1")
175
175
  def list(offset: nil, limit: nil, workflow_id: nil, parent_workflow_run_id: nil,
176
176
  statuses: nil, additional_metadata: nil, order_by_field: nil, order_by_direction: nil)
177
177
  @workflow_api.workflow_scheduled_list(
@@ -195,7 +195,7 @@ module Hatchet
195
195
  # @return [Object] The requested scheduled workflow instance
196
196
  # @raise [HatchetSdkRest::ApiError] If the API request fails
197
197
  # @example
198
- # scheduled = scheduled_client.get("scheduled-123")
198
+ # scheduled = hatchet.scheduled.get("scheduled-123")
199
199
  def get(scheduled_id)
200
200
  @workflow_api.workflow_scheduled_get(@config.tenant_id, scheduled_id)
201
201
  end
@@ -8,7 +8,7 @@ module Hatchet
8
8
  # from the Hatchet system.
9
9
  #
10
10
  # @example Getting the current tenant
11
- # tenant_info = tenant_client.get
11
+ # tenant_info = hatchet.tenant.get
12
12
  #
13
13
  # @since 0.1.0
14
14
  class Tenant
@@ -29,7 +29,7 @@ module Hatchet
29
29
  # @return [Object] The tenant details
30
30
  # @raise [HatchetSdkRest::ApiError] If the API request fails
31
31
  # @example
32
- # tenant = tenant_client.get
32
+ # tenant = hatchet.tenant.get
33
33
  def get
34
34
  @tenant_api.tenant_get(@config.tenant_id)
35
35
  end
@@ -8,10 +8,10 @@ module Hatchet
8
8
  # updating workers in the Hatchet system.
9
9
  #
10
10
  # @example Getting a worker
11
- # worker = workers_client.get("worker-id")
11
+ # worker = hatchet.workers.get("worker-id")
12
12
  #
13
13
  # @example Listing all workers
14
- # workers = workers_client.list
14
+ # workers = hatchet.workers.list
15
15
  #
16
16
  # @since 0.1.0
17
17
  class Workers
@@ -33,7 +33,7 @@ module Hatchet
33
33
  # @return [Object] The worker details
34
34
  # @raise [HatchetSdkRest::ApiError] If the API request fails
35
35
  # @example
36
- # worker = workers_client.get("worker-123")
36
+ # worker = hatchet.workers.get("worker-123")
37
37
  def get(worker_id)
38
38
  @worker_api.worker_get(worker_id)
39
39
  end
@@ -43,7 +43,7 @@ module Hatchet
43
43
  # @return [Object] A list of workers
44
44
  # @raise [HatchetSdkRest::ApiError] If the API request fails
45
45
  # @example
46
- # workers = workers_client.list
46
+ # workers = hatchet.workers.list
47
47
  def list
48
48
  @worker_api.worker_list(@config.tenant_id)
49
49
  end
@@ -55,7 +55,7 @@ module Hatchet
55
55
  # @return [Object] The updated worker
56
56
  # @raise [HatchetSdkRest::ApiError] If the API request fails
57
57
  # @example
58
- # updated = workers_client.update("worker-123", { is_paused: true })
58
+ # updated = hatchet.workers.update("worker-123", { is_paused: true })
59
59
  def update(worker_id, opts)
60
60
  update_request = HatchetSdkRest::UpdateWorkerRequest.new(opts)
61
61
  @worker_api.worker_update(worker_id, update_request)
@@ -8,10 +8,10 @@ module Hatchet
8
8
  # If you're looking for runs, use the Runs client instead.
9
9
  #
10
10
  # @example Getting a workflow
11
- # workflow = workflows_client.get("workflow-id")
11
+ # workflow = hatchet.workflows.get("workflow-id")
12
12
  #
13
13
  # @example Listing workflows
14
- # workflows = workflows_client.list(workflow_name: "my-workflow", limit: 10)
14
+ # workflows = hatchet.workflows.list(workflow_name: "my-workflow", limit: 10)
15
15
  #
16
16
  # @since 0.1.0
17
17
  class Workflows
@@ -33,7 +33,7 @@ module Hatchet
33
33
  # @return [Object] The workflow details
34
34
  # @raise [HatchetSdkRest::ApiError] If the API request fails
35
35
  # @example
36
- # workflow = workflows_client.get("workflow-123")
36
+ # workflow = hatchet.workflows.get("workflow-123")
37
37
  def get(workflow_id)
38
38
  @workflow_api.workflow_get(workflow_id)
39
39
  end
@@ -46,7 +46,7 @@ module Hatchet
46
46
  # @return [Object] A list of workflows
47
47
  # @raise [HatchetSdkRest::ApiError] If the API request fails
48
48
  # @example
49
- # workflows = workflows_client.list(workflow_name: "my-workflow", limit: 10, offset: 0)
49
+ # workflows = hatchet.workflows.list(workflow_name: "my-workflow", limit: 10, offset: 0)
50
50
  def list(workflow_name: nil, limit: nil, offset: nil)
51
51
  @workflow_api.workflow_list(
52
52
  @config.tenant_id,
@@ -65,7 +65,7 @@ module Hatchet
65
65
  # @return [Object] The workflow version
66
66
  # @raise [HatchetSdkRest::ApiError] If the API request fails
67
67
  # @example
68
- # version = workflows_client.get_version("workflow-123", version: "v2")
68
+ # version = hatchet.workflows.get_version("workflow-123", version: "v2")
69
69
  def get_version(workflow_id, version: nil)
70
70
  @workflow_api.workflow_version_get(workflow_id, { version: version })
71
71
  end
@@ -78,7 +78,7 @@ module Hatchet
78
78
  # @return [void]
79
79
  # @raise [HatchetSdkRest::ApiError] If the API request fails
80
80
  # @example
81
- # workflows_client.delete("workflow-123")
81
+ # hatchet.workflows.delete("workflow-123")
82
82
  def delete(workflow_id)
83
83
  @workflow_api.workflow_delete(workflow_id)
84
84
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Hatchet
4
- VERSION = "0.6.0"
4
+ VERSION = "0.7.0"
5
5
  end
@@ -98,10 +98,23 @@ module Hatchet
98
98
  @id ||= resolve_workflow_id
99
99
  end
100
100
 
101
- # Define a task within this workflow
101
+ # Define a task within this workflow. The block receives the workflow input
102
+ # and a {Context} object, and its return value (a Hash) becomes the task
103
+ # output.
102
104
  #
103
- # @param name [Symbol, String] Task name
104
- # @param opts [Hash] Task options (parents:, execution_timeout:, retries:, etc.)
105
+ # @param name [Symbol, String] The name of the task
106
+ # @option opts [Array<Task, Symbol>] :parents ([]) A list of tasks that are parents of the task. Note: parents must be defined before their children
107
+ # @option opts [Integer, String, nil] :execution_timeout (nil) The maximum time to wait for the task to complete, in seconds or as a duration string (e.g. "60s")
108
+ # @option opts [Integer, String, nil] :schedule_timeout (nil) The maximum time to wait for the task to be scheduled
109
+ # @option opts [Integer, nil] :retries (nil) The number of times to retry the task before failing
110
+ # @option opts [Float, nil] :backoff_factor (nil) The backoff factor for controlling exponential backoff in retries
111
+ # @option opts [Integer, nil] :backoff_max_seconds (nil) The maximum number of seconds to allow retries with exponential backoff to continue
112
+ # @option opts [Array<RateLimit>] :rate_limits ([]) A list of rate limit configurations for the task
113
+ # @option opts [ConcurrencyExpression, Array<ConcurrencyExpression>, nil] :concurrency (nil) A concurrency expression (or list of them) controlling the concurrency settings for this task
114
+ # @option opts [Hash, nil] :desired_worker_labels (nil) A hash of desired worker labels that determine to which worker the task should be assigned
115
+ # @option opts [Array] :wait_for ([]) A list of conditions that must be met before the task can run
116
+ # @option opts [Array] :skip_if ([]) A list of conditions that, if met, will cause the task to be skipped
117
+ # @option opts [Hash, nil] :deps (nil) Dependency providers to inject into the task's context
105
118
  # @yield [input, ctx] The task execution block
106
119
  # @return [Task] The created task
107
120
  def task(name, **opts, &)
@@ -238,55 +251,65 @@ module Hatchet
238
251
  ::V1::CreateWorkflowVersionRequest.new(**args)
239
252
  end
240
253
 
241
- # Run this workflow synchronously
254
+ # Run this workflow synchronously and wait for it to complete.
242
255
  #
243
- # @param input [Hash] Workflow input
244
- # @param options [TriggerWorkflowOptions, nil] Trigger options
245
- # @return [Hash] The workflow run output
256
+ # @param input [Hash] The input data for the workflow
257
+ # @param options [TriggerWorkflowOptions, nil] Additional options for workflow execution, such as +additional_metadata:+ and +priority:+
258
+ # @return [Hash] The workflow run output, keyed by task name (e.g. `{"step1" => {...}, "step2" => {...}}`)
259
+ # @raise [Hatchet::Error] If no client is associated with the workflow
260
+ # @raise [Hatchet::FailedRunError] If the workflow run failed
246
261
  def run(input = {}, options: nil)
247
262
  raise Error, "No client associated with workflow #{@name}" unless @client
248
263
 
249
264
  @client.admin.trigger_workflow(self, input, options: options)
250
265
  end
251
266
 
252
- # Run this workflow without waiting for the result
267
+ # Trigger a workflow run without waiting for it to complete. Useful for
268
+ # starting a run and immediately returning a reference to it without
269
+ # blocking while the workflow runs.
253
270
  #
254
- # @param input [Hash] Workflow input
255
- # @param options [TriggerWorkflowOptions, nil] Trigger options
256
- # @return [WorkflowRunRef]
271
+ # @param input [Hash] The input data for the workflow
272
+ # @param options [TriggerWorkflowOptions, nil] Additional options for workflow execution
273
+ # @return [WorkflowRunRef] A reference to the workflow run, whose +result+ method blocks until the run completes
274
+ # @raise [Hatchet::Error] If no client is associated with the workflow
257
275
  def run_no_wait(input = {}, options: nil)
258
276
  raise Error, "No client associated with workflow #{@name}" unless @client
259
277
 
260
278
  @client.admin.trigger_workflow_no_wait(self, input, options: options)
261
279
  end
262
280
 
263
- # Run many instances of this workflow in bulk
281
+ # Run this workflow in bulk and wait for all runs to complete. Runs are
282
+ # triggered via bulk gRPC triggering (batched by 1000) and results are
283
+ # collected concurrently.
264
284
  #
265
- # @param items [Array<Hash>] Bulk run items
266
- # @param return_exceptions [Boolean] Return exceptions instead of raising
267
- # @return [Array] Results
285
+ # @param items [Array<Hash>] A list of bulk run items, as created by {#create_bulk_run_item}
286
+ # @param return_exceptions [Boolean] If +true+, exceptions are returned as part of the results instead of being raised
287
+ # @return [Array] A list of results for each workflow run
288
+ # @raise [Hatchet::Error] If no client is associated with the workflow
268
289
  def run_many(items, return_exceptions: false)
269
290
  raise Error, "No client associated with workflow #{@name}" unless @client
270
291
 
271
292
  @client.admin.trigger_workflow_many(self, items, return_exceptions: return_exceptions)
272
293
  end
273
294
 
274
- # Run many instances without waiting for results
295
+ # Run this workflow in bulk without waiting for the runs to complete.
275
296
  #
276
- # @param items [Array<Hash>] Bulk run items
277
- # @return [Array<WorkflowRunRef>]
297
+ # @param items [Array<Hash>] A list of bulk run items, as created by {#create_bulk_run_item}
298
+ # @return [Array<WorkflowRunRef>] A list of references to the triggered workflow runs
299
+ # @raise [Hatchet::Error] If no client is associated with the workflow
278
300
  def run_many_no_wait(items)
279
301
  raise Error, "No client associated with workflow #{@name}" unless @client
280
302
 
281
303
  @client.admin.trigger_workflow_many_no_wait(self, items)
282
304
  end
283
305
 
284
- # Create a bulk run item for use with run_many
306
+ # Create a bulk run item for this workflow, intended to be used with the
307
+ # {#run_many} methods.
285
308
  #
286
- # @param input [Hash] Input data
287
- # @param key [String, nil] Deduplication key
288
- # @param options [TriggerWorkflowOptions, nil] Trigger options
289
- # @return [Hash] Bulk run item
309
+ # @param input [Hash] The input data for the workflow
310
+ # @param key [String, nil] The key for the workflow run, used for identification and deduplication
311
+ # @param options [TriggerWorkflowOptions, nil] Additional options for the workflow run
312
+ # @return [Hash] A bulk run item that can be passed to the +run_many+ methods
290
313
  def create_bulk_run_item(input: {}, key: nil, options: nil)
291
314
  item = { input: input }
292
315
  item[:key] = key if key
@@ -294,24 +317,26 @@ module Hatchet
294
317
  item
295
318
  end
296
319
 
297
- # Schedule this workflow for future execution
320
+ # Schedule this workflow to run at a specific time.
298
321
  #
299
- # @param time [Time] When to execute
300
- # @param input [Hash] Workflow input
301
- # @param options [ScheduleTriggerWorkflowOptions, nil] Schedule options
302
- # @return [Object] Schedule result
322
+ # @param time [Time] When to execute the workflow
323
+ # @param input [Hash] The input data for the workflow
324
+ # @param options [ScheduleTriggerWorkflowOptions, nil] Additional schedule options
325
+ # @return [Object] The schedule response from the Hatchet engine
326
+ # @raise [Hatchet::Error] If no client is associated with the workflow
303
327
  def schedule(time, input: {}, options: nil)
304
328
  raise Error, "No client associated with workflow #{@name}" unless @client
305
329
 
306
330
  @client.admin.schedule_workflow(self, time, input: input, options: options)
307
331
  end
308
332
 
309
- # Create a cron trigger for this workflow
333
+ # Create a cron trigger for this workflow.
310
334
  #
311
- # @param cron_name [String] Name for the cron
312
- # @param expression [String] Cron expression
313
- # @param input [Hash] Workflow input
314
- # @return [Object] Cron result
335
+ # @param cron_name [String] The name of the cron job
336
+ # @param expression [String] The cron expression that defines the schedule
337
+ # @param input [Hash] The input data for the workflow
338
+ # @return [Object] The created cron workflow trigger
339
+ # @raise [Hatchet::Error] If no client is associated with the workflow
315
340
  def create_cron(cron_name, expression, input: {})
316
341
  raise Error, "No client associated with workflow #{@name}" unless @client
317
342