ask-graph 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +41 -0
- data/lib/ask/graph/runner.rb +3 -3
- data/lib/ask/graph/version.rb +1 -1
- data/lib/ask/graph.rb +38 -5
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c3062914e848e9fea15dd9b02bd001946b7a3fd0ab015a1805b4e21a371b68bf
|
|
4
|
+
data.tar.gz: 17866f6bfaf40d6e195c71655ac134430747e3690ce32c355036a8e30a62bbf1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ac9dad679a58246c1bd04d67de6812e9126f8f341edad4a72e842b80b759bcf2e020a2ad0c5bedd625eff861f22f0cbb224d4d2dc058a136d4c13087c4420248
|
|
7
|
+
data.tar.gz: b0f7285fd1e447c3f48e06d061aa441f64bb37de1952022e22e44835c3b549c639bceec13d9a690d0d14becb5eb724e1d2f31c05ea47a514ba2be57d9680de3b
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,44 @@
|
|
|
1
|
+
## [0.4.0] — 2026-07-27
|
|
2
|
+
|
|
3
|
+
### Changed
|
|
4
|
+
|
|
5
|
+
- **`checkpoint_store:` renamed to `storage:`** — shorter, more general name
|
|
6
|
+
for the backend that persists checkpoint data for crash recovery.
|
|
7
|
+
|
|
8
|
+
```ruby
|
|
9
|
+
# Before
|
|
10
|
+
MyGraph.call(input, checkpoint_store: RedisPool.new)
|
|
11
|
+
g.new(input, checkpoint_store: RedisPool.new)
|
|
12
|
+
|
|
13
|
+
# After
|
|
14
|
+
MyGraph.call(input, storage: RedisPool.new)
|
|
15
|
+
g.new(input, storage: RedisPool.new)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
### Added
|
|
19
|
+
|
|
20
|
+
- **Class-level `storage`** — set once at the class level instead of passing
|
|
21
|
+
per-call. Works the same as `timeout`: per-call → graph class → global.
|
|
22
|
+
|
|
23
|
+
```ruby
|
|
24
|
+
# Global default for all graphs
|
|
25
|
+
Ask::Graph.storage RedisPool.new
|
|
26
|
+
|
|
27
|
+
# Per-graph override
|
|
28
|
+
class MyGraph < Ask::Graph
|
|
29
|
+
storage PostgresStore.new
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Per-call override (overrides everything)
|
|
33
|
+
MyGraph.call(input, storage: InMemory.new)
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Falls back to `Ask::State::Memory.new` when nothing is configured.
|
|
37
|
+
|
|
38
|
+
### Tested
|
|
39
|
+
|
|
40
|
+
- 70 tests, 92 assertions, 0 failures
|
|
41
|
+
|
|
1
42
|
## [0.3.0] — 2026-07-27
|
|
2
43
|
|
|
3
44
|
### Added
|
data/lib/ask/graph/runner.rb
CHANGED
|
@@ -21,16 +21,16 @@ module Ask
|
|
|
21
21
|
attr_reader :declarations, :store
|
|
22
22
|
|
|
23
23
|
# @param declarations [Array<Hash>] step declarations
|
|
24
|
-
# @param
|
|
24
|
+
# @param storage [#set, #get, #delete] key-value store for checkpoint data
|
|
25
25
|
# @param hooks [Hash] lifecycle hook method names
|
|
26
26
|
# @param graph_instance [Object] the graph instance (for hooks)
|
|
27
27
|
# @param default_timeout [Integer, nil] fallback timeout for steps with no explicit timeout
|
|
28
|
-
def initialize(declarations,
|
|
28
|
+
def initialize(declarations, storage: nil,
|
|
29
29
|
hooks: { before_step: [], after_step: [], on_failure: [] },
|
|
30
30
|
graph_instance: nil,
|
|
31
31
|
default_timeout: nil)
|
|
32
32
|
@declarations = declarations
|
|
33
|
-
@store =
|
|
33
|
+
@store = storage
|
|
34
34
|
@hooks = hooks
|
|
35
35
|
@graph = graph_instance
|
|
36
36
|
@default_timeout = default_timeout
|
data/lib/ask/graph/version.rb
CHANGED
data/lib/ask/graph.rb
CHANGED
|
@@ -77,6 +77,39 @@ module Ask
|
|
|
77
77
|
end
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
+
# --- Storage ---
|
|
81
|
+
|
|
82
|
+
# Set or get the default storage backend for checkpoint data.
|
|
83
|
+
# The storage object must respond to +#set(key, value)+ and +#get(key)+.
|
|
84
|
+
#
|
|
85
|
+
# Setting on {Ask::Graph} itself applies to all graphs that don't set
|
|
86
|
+
# their own storage — a global default.
|
|
87
|
+
#
|
|
88
|
+
# @example Global default for all graphs
|
|
89
|
+
# Ask::Graph.storage RedisPool.new
|
|
90
|
+
#
|
|
91
|
+
# @example Per-graph override
|
|
92
|
+
# class MyGraph < Ask::Graph
|
|
93
|
+
# storage PostgresStore.new
|
|
94
|
+
# end
|
|
95
|
+
#
|
|
96
|
+
# @example Per-call override
|
|
97
|
+
# MyGraph.call(input, storage: InMemory.new)
|
|
98
|
+
#
|
|
99
|
+
# @param store [Object, nil] a backend that responds to +#set+ and +#get+
|
|
100
|
+
# @return [Object, nil] the current storage for this graph
|
|
101
|
+
def storage(store = :not_set)
|
|
102
|
+
if store == :not_set
|
|
103
|
+
if instance_variable_defined?(:@storage)
|
|
104
|
+
@storage
|
|
105
|
+
elsif superclass.respond_to?(:storage)
|
|
106
|
+
superclass.storage
|
|
107
|
+
end
|
|
108
|
+
else
|
|
109
|
+
@storage = store
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
|
|
80
113
|
# --- Lifecycle hooks ---
|
|
81
114
|
|
|
82
115
|
def lifecycle_hooks
|
|
@@ -142,8 +175,8 @@ module Ask
|
|
|
142
175
|
end
|
|
143
176
|
|
|
144
177
|
# Convenience: create instance and call.
|
|
145
|
-
def call(input = nil,
|
|
146
|
-
new(input,
|
|
178
|
+
def call(input = nil, storage: nil)
|
|
179
|
+
new(input, storage: storage).call
|
|
147
180
|
end
|
|
148
181
|
alias run call
|
|
149
182
|
|
|
@@ -163,12 +196,12 @@ module Ask
|
|
|
163
196
|
end
|
|
164
197
|
end
|
|
165
198
|
|
|
166
|
-
def initialize(input = nil,
|
|
199
|
+
def initialize(input = nil, storage: nil)
|
|
167
200
|
@input = input
|
|
168
|
-
store =
|
|
201
|
+
store = storage || self.class.storage || Ask::State::Memory.new
|
|
169
202
|
hooks = self.class.lifecycle_hooks
|
|
170
203
|
@runner = Runner.new(self.class.declarations,
|
|
171
|
-
|
|
204
|
+
storage: store,
|
|
172
205
|
hooks: hooks,
|
|
173
206
|
graph_instance: self,
|
|
174
207
|
default_timeout: self.class.timeout)
|