Skip to content

Commit f78bdfd

Browse files
authored
Add Ruby eviction snippets (#3772)
1 parent 11775af commit f78bdfd

3 files changed

Lines changed: 28 additions & 4 deletions

File tree

examples/ruby/durable_eviction/worker.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
CAPACITY_SLEEP_SECONDS = 20
1010
EVENT_KEY = "durable-eviction:event"
1111

12+
# > Eviction Policy
1213
EVICTION_POLICY = Hatchet::EvictionPolicy.new(
1314
ttl: EVICTION_TTL_SECONDS,
1415
allow_capacity_eviction: true,
@@ -38,6 +39,7 @@
3839
{ "sleep_for" => sleep_for, "status" => "completed" }
3940
end
4041

42+
# > Evictable Sleep
4143
EVICTABLE_SLEEP = HATCHET.durable_task(
4244
name: "evictable_sleep",
4345
execution_timeout: 300,
@@ -102,6 +104,7 @@
102104
{ "status" => "completed" }
103105
end
104106

107+
# > Non Evictable Sleep
105108
NON_EVICTABLE_SLEEP = HATCHET.durable_task(
106109
name: "non_evictable_sleep",
107110
execution_timeout: 300,

frontend/docs/pages/v1/task-eviction.mdx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Every durable task can configure an **eviction policy**, which tells Hatchet how
2424

2525
Start by declaring a policy:
2626

27-
<UniversalTabs items={["Python", "Typescript", "Go"]}>
27+
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]}>
2828
<Tabs.Tab title="Python">
2929

3030
<Snippet src={snippets.python.durable_eviction.worker.eviction_policy} />
@@ -39,12 +39,17 @@ Start by declaring a policy:
3939

4040
<Snippet src={snippets.go.durable.eviction.main.eviction_policy} />
4141

42+
</Tabs.Tab>
43+
<Tabs.Tab title="Ruby">
44+
45+
<Snippet src={snippets.ruby.durable_eviction.worker.eviction_policy} />
46+
4247
</Tabs.Tab>
4348
</UniversalTabs>
4449

4550
Then attach it to a durable task. Any time the task enters a wait (sleep, event wait, child spawn) the policy's TTL and capacity-eviction settings are honored:
4651

47-
<UniversalTabs items={["Python", "Typescript", "Go"]} variant="hidden">
52+
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
4853
<Tabs.Tab title="Python">
4954

5055
<Snippet src={snippets.python.durable_eviction.worker.evictable_sleep} />
@@ -59,12 +64,17 @@ Then attach it to a durable task. Any time the task enters a wait (sleep, event
5964

6065
<Snippet src={snippets.go.durable.eviction.main.evictable_sleep} />
6166

67+
</Tabs.Tab>
68+
<Tabs.Tab title="Ruby">
69+
70+
<Snippet src={snippets.ruby.durable_eviction.worker.evictable_sleep} />
71+
6272
</Tabs.Tab>
6373
</UniversalTabs>
6474

6575
To opt a durable task out of eviction entirely, set `allowCapacityEviction` to `false` and leave the TTL unset. The task will hold its slot through waits:
6676

67-
<UniversalTabs items={["Python", "Typescript", "Go"]} variant="hidden">
77+
<UniversalTabs items={["Python", "Typescript", "Go", "Ruby"]} variant="hidden">
6878
<Tabs.Tab title="Python">
6979

7080
<Snippet src={snippets.python.durable_eviction.worker.non_evictable_sleep} />
@@ -81,6 +91,11 @@ To opt a durable task out of eviction entirely, set `allowCapacityEviction` to `
8191

8292
<Snippet src={snippets.go.durable.eviction.main.non_evictable_sleep} />
8393

94+
</Tabs.Tab>
95+
<Tabs.Tab title="Ruby">
96+
97+
<Snippet src={snippets.ruby.durable_eviction.worker.non_evictable_sleep} />
98+
8499
</Tabs.Tab>
85100
</UniversalTabs>
86101

sdks/ruby/examples/durable_eviction/worker.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# frozen_string_literal: true
1+
frontend/docs/pages/v1/task-eviction.mdx# frozen_string_literal: true
22

33
require "hatchet-sdk"
44

@@ -9,11 +9,13 @@
99
CAPACITY_SLEEP_SECONDS = 20
1010
EVENT_KEY = "durable-eviction:event"
1111

12+
# > Eviction Policy
1213
EVICTION_POLICY = Hatchet::EvictionPolicy.new(
1314
ttl: EVICTION_TTL_SECONDS,
1415
allow_capacity_eviction: true,
1516
priority: 0,
1617
)
18+
# !!
1719

1820
CAPACITY_EVICTION_POLICY = Hatchet::EvictionPolicy.new(
1921
ttl: nil,
@@ -38,6 +40,7 @@
3840
{ "sleep_for" => sleep_for, "status" => "completed" }
3941
end
4042

43+
# > Evictable Sleep
4144
EVICTABLE_SLEEP = HATCHET.durable_task(
4245
name: "evictable_sleep",
4346
execution_timeout: 300,
@@ -46,6 +49,7 @@
4649
ctx.sleep_for(duration: LONG_SLEEP_SECONDS)
4750
{ "status" => "completed" }
4851
end
52+
# !!
4953

5054
EVICTABLE_WAIT_FOR_EVENT = HATCHET.durable_task(
5155
name: "evictable_wait_for_event",
@@ -102,6 +106,7 @@
102106
{ "status" => "completed" }
103107
end
104108

109+
# > Non Evictable Sleep
105110
NON_EVICTABLE_SLEEP = HATCHET.durable_task(
106111
name: "non_evictable_sleep",
107112
execution_timeout: 300,
@@ -110,6 +115,7 @@
110115
ctx.sleep_for(duration: 10)
111116
{ "status" => "completed" }
112117
end
118+
# !!
113119

114120
def main
115121
worker = HATCHET.worker(

0 commit comments

Comments
 (0)