ask-graph 0.2.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 965f606d4e8a059634acd10ed0e2fbf96c159ba487d30f5f2edcec9bb1b75b89
4
- data.tar.gz: b419551a611da8cd81eb7ab0d31bdf0c8213d8ed829e6a30981fe0d561938e84
3
+ metadata.gz: 59959ae9ec12f0d79aecfe21ae07748baa067bb47efb9c519d291dd352032873
4
+ data.tar.gz: ea54f68d9693259b6fbe2833693391e7844c26b9f442551af09fe3d1e4d6b84d
5
5
  SHA512:
6
- metadata.gz: fee1727d038a4a74c11571ad040b86cb1d1b18bbeda4e9e3e59c46ae1a9d2eeab34d9660fbc9674e94601a14704d014e71bf782f61848c4e681bf3efd5e8f896
7
- data.tar.gz: 9f943406f882e4e4344870b05b3cc945bf03555095f0f581456b22a9f1b8596acc5091c72d6191c4e41ed0651e6c5a09a895c49b4ae3fc4a8550dc6f0fdd3c84
6
+ metadata.gz: 221a7565d2feb4ac3769793dbb510687b56f0058bc259ecf94a32acb59e4d8dcebe23a4d7cc14888a6001ffc53a3e06bbc940e45032138dcd734fb6476b76a28
7
+ data.tar.gz: 68e22b21cffae4f146781926d89dd7c767f31234212181ce60707f9dd8e35ec90841f868677517d772a0221ca80fe7a53b15f93a7a067f6c5a280c4ebd5e7ae4
data/CHANGELOG.md CHANGED
@@ -1,3 +1,33 @@
1
+ ## [0.3.0] — 2026-07-27
2
+
3
+ ### Added
4
+
5
+ - **Class-level `timeout`** — set a default timeout for all steps in a graph.
6
+ Steps without an explicit `timeout:` option inherit the class default.
7
+
8
+ ```ruby
9
+ class MyGraph < Ask::Graph
10
+ timeout 30
11
+ step FastOp # uses 30s
12
+ step SlowOp, timeout: 120 # overrides
13
+ end
14
+ ```
15
+
16
+ - **Global default timeout** — `Ask::Graph.timeout 30` applies to all graphs
17
+ that don't set their own `timeout`. Resolution order: step option → graph
18
+ class → `Ask::Graph`.
19
+
20
+ ```ruby
21
+ Ask::Graph.timeout 30
22
+ ```
23
+
24
+ - **Child override and clearing** — child graphs can override or clear
25
+ (`timeout nil`) the parent's default.
26
+
27
+ ### Tested
28
+
29
+ - 62 tests, 83 assertions, 0 failures
30
+
1
31
  ## [0.2.0] — 2026-07-29
2
32
 
3
33
  ### Added
@@ -24,13 +24,16 @@ module Ask
24
24
  # @param checkpoint_store [#set, #get, #delete] key-value store
25
25
  # @param hooks [Hash] lifecycle hook method names
26
26
  # @param graph_instance [Object] the graph instance (for hooks)
27
+ # @param default_timeout [Integer, nil] fallback timeout for steps with no explicit timeout
27
28
  def initialize(declarations, checkpoint_store: nil,
28
29
  hooks: { before_step: [], after_step: [], on_failure: [] },
29
- graph_instance: nil)
30
+ graph_instance: nil,
31
+ default_timeout: nil)
30
32
  @declarations = declarations
31
33
  @store = checkpoint_store
32
34
  @hooks = hooks
33
35
  @graph = graph_instance
36
+ @default_timeout = default_timeout
34
37
  @completed_steps = []
35
38
  end
36
39
 
@@ -90,6 +93,7 @@ module Ask
90
93
  end
91
94
 
92
95
  def run_with_timeout(decl, context, timeout_value)
96
+ timeout_value ||= @default_timeout
93
97
  if timeout_value
94
98
  ::Timeout.timeout(timeout_value) { execute_step(decl, context) }
95
99
  else
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ask
4
4
  class Graph
5
- VERSION = "0.2.0"
5
+ VERSION = "0.3.0"
6
6
  end
7
7
  end
data/lib/ask/graph.rb CHANGED
@@ -46,6 +46,37 @@ module Ask
46
46
  subclass.instance_variable_set(:@lifecycle_hooks, lifecycle_hooks.dup)
47
47
  end
48
48
 
49
+ # --- Timeout ---
50
+
51
+ # Set or get the default timeout (in seconds) for steps in this graph.
52
+ # Steps without an explicit +timeout:+ option will inherit this value.
53
+ # Setting on {Ask::Graph} itself applies to all graphs that don't set
54
+ # their own default — a global default.
55
+ #
56
+ # @example Global default for all graphs
57
+ # Ask::Graph.timeout 30
58
+ #
59
+ # @example Per-graph override
60
+ # class MyGraph < Ask::Graph
61
+ # timeout 15
62
+ # step FastOp # uses 15s
63
+ # step SlowOp, timeout: 60 # overrides
64
+ # end
65
+ #
66
+ # @param seconds [Integer, nil] timeout in seconds, or nil to clear
67
+ # @return [Integer, nil] the current default timeout for this graph
68
+ def timeout(seconds = :not_set)
69
+ if seconds == :not_set
70
+ if instance_variable_defined?(:@timeout)
71
+ @timeout
72
+ elsif superclass.respond_to?(:timeout)
73
+ superclass.timeout
74
+ end
75
+ else
76
+ @timeout = seconds
77
+ end
78
+ end
79
+
49
80
  # --- Lifecycle hooks ---
50
81
 
51
82
  def lifecycle_hooks
@@ -139,7 +170,8 @@ module Ask
139
170
  @runner = Runner.new(self.class.declarations,
140
171
  checkpoint_store: store,
141
172
  hooks: hooks,
142
- graph_instance: self)
173
+ graph_instance: self,
174
+ default_timeout: self.class.timeout)
143
175
  @context = nil
144
176
  end
145
177
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ask-graph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kaka Ruto