Diffinery

homeflare/celldpublic

celld/docs/services/cron-triggers-flow.svg
148 lines · 9.8 KBRaw History
1<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 440 676" role="img" aria-labelledby="cronFlowTitle cronFlowDesc">
2 <title id="cronFlowTitle">Every node arms one reserved cron cell, its single alarm row carries the earliest occurrence, a shared deadline runs one invocation for each matching expression, and the re-arm takes the earlier of the next occurrence and the failure backoff</title>
3 <desc id="cronFlowDesc">The first panel shows three nodes of one fleet. Each node calls the same
4reserved cell, named .cron:cron from the class and the script name, once after
5its deployment loads. The ownership record in the fleet bucket accepts one
6caller, and the other nodes route to that owner, so celld needs no election and
7no reserved cron node. The second panel shows three cron expressions of one
8script at 12:35 UTC. Two of them come due at 13:00 and one comes due on the
9next Monday at 09:00, and the one alarm row of the cell arms for 13:00, the
10earliest occurrence across the whole list. The third panel shows the 13:00
11deadline firing. Both expressions that match that minute get their own call of
12scheduled(controller, env, ctx), each with its own controller.cron, and the two
13calls run one after another inside the cell because a cell runs one event at a
14time. controller.scheduledTime is 13:00 for both calls and never the instant
15the attempt started. The fourth panel shows the re-arm after a failed 13:00
16run. For the expression */30 * * * * the retry backoff of 4 seconds is earlier
17than the next occurrence at 13:30, so the retry is armed. For the expression
18* * * * * the next occurrence at 13:01 is earlier than a grown backoff of 128
19seconds, so the occurrence is armed and the retry is dropped. A backoff
20therefore never delays or skips a scheduled occurrence.</desc>
21 <style>
22 svg { font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Helvetica, Arial, sans-serif; }
23 text { font-size: 13px; fill: currentColor; }
24 tspan { fill: currentColor; }
25 .mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
26 .lead { font-weight: 600; }
27 .sm { font-size: 12px; }
28 .d-ink { color: #121212; }
29 .d-soft { color: #3d3b37; }
30 .d-faint { color: #6e6a62; }
31 .d-acc { color: #10803f; }
32 .d-panel { color: #ffffff; }
33 .d-sunk { color: #f0eee8; }
34 .d-tint { color: #d6efdf; }
35 @media (prefers-color-scheme: dark) {
36 .d-ink { color: #efede7; }
37 .d-soft { color: #c9c6be; }
38 .d-faint { color: #928e85; }
39 .d-acc { color: #3fc472; }
40 .d-panel { color: #1a1a19; }
41 .d-sunk { color: #232321; }
42 .d-tint { color: #10301d; }
43 }
44 </style>
45 <defs>
46 <marker id="cron-arrow" viewBox="0 0 10 10" refX="9" refY="5" markerWidth="6"
47 markerHeight="6" orient="auto-start-reverse">
48 <path class="d-soft" fill="currentColor" d="M0 0 L10 5 L0 10 z" />
49 </marker>
50 </defs>
51
52 <!-- Panel one: the fan-in. Every node arms, and one ownership CAS decides. -->
53 <rect class="d-sunk" fill="currentColor" x="8" y="8" width="424" height="186" rx="10" />
54 <rect class="d-faint" fill="none" stroke="currentColor" x="8" y="8" width="424" height="186" rx="10" />
55 <text class="d-ink lead" fill="currentColor" x="22" y="32">Every node arms the same reserved cell</text>
56 <text class="d-faint sm" fill="currentColor" x="22" y="50">no election, and no reserved cron node</text>
57
58 <g>
59 <rect class="d-panel" fill="currentColor" x="22" y="64" width="122" height="38" rx="8" />
60 <rect class="d-soft" fill="none" stroke="currentColor" x="22" y="64" width="122" height="38" rx="8" />
61 <text class="d-ink" fill="currentColor" x="83" y="88" text-anchor="middle">node A</text>
62 <rect class="d-panel" fill="currentColor" x="159" y="64" width="122" height="38" rx="8" />
63 <rect class="d-soft" fill="none" stroke="currentColor" x="159" y="64" width="122" height="38" rx="8" />
64 <text class="d-ink" fill="currentColor" x="220" y="88" text-anchor="middle">node B</text>
65 <rect class="d-panel" fill="currentColor" x="296" y="64" width="122" height="38" rx="8" />
66 <rect class="d-soft" fill="none" stroke="currentColor" x="296" y="64" width="122" height="38" rx="8" />
67 <text class="d-ink" fill="currentColor" x="357" y="88" text-anchor="middle">node C</text>
68 </g>
69
70 <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5">
71 <path d="M83 102 V122 H220" />
72 <path d="M357 102 V122 H220" />
73 <path d="M220 102 V136" marker-end="url(#cron-arrow)" />
74 </g>
75 <text class="d-faint sm" fill="currentColor" x="228" y="118">arm</text>
76
77 <rect class="d-tint" fill="currentColor" x="110" y="140" width="220" height="46" rx="8" />
78 <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="110" y="140" width="220" height="46" rx="8" />
79 <text class="d-ink mono" fill="currentColor" x="220" y="162" text-anchor="middle">.cron:cron</text>
80 <text class="d-soft sm" fill="currentColor" x="220" y="179" text-anchor="middle">one owner, by ownership CAS</text>
81
82 <!-- Panel two: many expressions, one alarm row, the earliest deadline. -->
83 <text class="d-ink lead" fill="currentColor" x="22" y="226">One alarm row holds one deadline</text>
84 <text class="d-faint sm mono" fill="currentColor" x="22" y="244">now 12:35 UTC</text>
85
86 <text class="d-soft mono" fill="currentColor" x="26" y="272">*/30 * * * *</text>
87 <text class="d-ink mono" fill="currentColor" x="150" y="272">13:00</text>
88 <text class="d-soft mono" fill="currentColor" x="26" y="292">0 * * * *</text>
89 <text class="d-ink mono" fill="currentColor" x="150" y="292">13:00</text>
90 <text class="d-soft mono" fill="currentColor" x="26" y="312">0 9 * * MON</text>
91 <text class="d-faint mono" fill="currentColor" x="150" y="312">Mon 09:00</text>
92
93 <path class="d-acc" fill="none" stroke="currentColor" stroke-width="2"
94 d="M214 260 H222 V298 H214" />
95 <path class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5"
96 d="M224 279 H244" marker-end="url(#cron-arrow)" />
97
98 <rect class="d-panel" fill="currentColor" x="252" y="253" width="178" height="52" rx="8" />
99 <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="252" y="253" width="178" height="52" rx="8" />
100 <text class="d-ink" fill="currentColor" x="341" y="276" text-anchor="middle">armed for 13:00</text>
101 <text class="d-soft sm" fill="currentColor" x="341" y="294" text-anchor="middle">the earliest of the three</text>
102
103 <!-- Panel three: the fan-out. One deadline, one call per matching expression. -->
104 <text class="d-ink lead" fill="currentColor" x="22" y="350">A deadline that two expressions share runs twice</text>
105
106 <rect class="d-tint" fill="currentColor" x="22" y="364" width="142" height="52" rx="8" />
107 <rect class="d-acc" fill="none" stroke="currentColor" stroke-width="2" x="22" y="364" width="142" height="52" rx="8" />
108 <text class="d-ink" fill="currentColor" x="93" y="388" text-anchor="middle">the alarm fires</text>
109 <text class="d-soft sm mono" fill="currentColor" x="93" y="406" text-anchor="middle">13:00 UTC</text>
110
111 <g class="d-soft" fill="none" stroke="currentColor" stroke-width="1.5">
112 <path d="M164 390 H182 V380 H194" marker-end="url(#cron-arrow)" />
113 <path d="M164 390 H182 V436 H194" marker-end="url(#cron-arrow)" />
114 </g>
115
116 <rect class="d-panel" fill="currentColor" x="200" y="356" width="232" height="48" rx="8" />
117 <rect class="d-soft" fill="none" stroke="currentColor" x="200" y="356" width="232" height="48" rx="8" />
118 <text class="d-ink mono" fill="currentColor" x="316" y="378" text-anchor="middle">scheduled(controller, env, ctx)</text>
119 <text class="d-acc sm mono" fill="currentColor" x="316" y="396" text-anchor="middle">cron: "*/30 * * * *"</text>
120
121 <rect class="d-panel" fill="currentColor" x="200" y="412" width="232" height="48" rx="8" />
122 <rect class="d-soft" fill="none" stroke="currentColor" x="200" y="412" width="232" height="48" rx="8" />
123 <text class="d-ink mono" fill="currentColor" x="316" y="434" text-anchor="middle">scheduled(controller, env, ctx)</text>
124 <text class="d-acc sm mono" fill="currentColor" x="316" y="452" text-anchor="middle">cron: "0 * * * *"</text>
125
126 <text class="d-soft sm" fill="currentColor" x="22" y="436">one after the other,</text>
127 <text class="d-soft sm" fill="currentColor" x="22" y="452">inside the one cell</text>
128 <text class="d-faint sm" fill="currentColor" x="22" y="486">scheduledTime is the occurrence 13:00 for both calls, never the</text>
129 <text class="d-faint sm" fill="currentColor" x="22" y="502">instant an attempt started</text>
130
131 <!-- Panel four: the re-arm race, where the answer flips with the interval. -->
132 <text class="d-ink lead" fill="currentColor" x="22" y="536">The re-arm takes whichever deadline is earlier</text>
133 <text class="d-faint sm" fill="currentColor" x="22" y="554">both lines start at a failed 13:00 run</text>
134
135 <text class="d-soft mono" fill="currentColor" x="22" y="586">*/30 * * * *</text>
136 <path class="d-faint" fill="none" stroke="currentColor" stroke-width="1.5" d="M120 582 H424" />
137 <path class="d-faint" fill="none" stroke="currentColor" d="M170 574 V590 M390 574 V590" />
138 <circle class="d-acc" fill="currentColor" cx="170" cy="582" r="5" />
139 <text class="d-acc sm" fill="currentColor" x="170" y="606" text-anchor="middle">retry +4 s</text>
140 <text class="d-faint sm" fill="currentColor" x="424" y="606" text-anchor="end">next 13:30</text>
141
142 <text class="d-soft mono" fill="currentColor" x="22" y="638">* * * * *</text>
143 <path class="d-faint" fill="none" stroke="currentColor" stroke-width="1.5" d="M120 634 H424" />
144 <path class="d-faint" fill="none" stroke="currentColor" d="M210 626 V642 M330 626 V642" />
145 <circle class="d-acc" fill="currentColor" cx="210" cy="634" r="5" />
146 <text class="d-acc sm" fill="currentColor" x="210" y="658" text-anchor="middle">next 13:01</text>
147 <text class="d-faint sm" fill="currentColor" x="424" y="658" text-anchor="end">retry +128 s</text>
148</svg>