bitfab 0.58.4 → 0.59.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: 13b552211978874936f8b732245e948396758a5adf6d0485859cf98748bf4933
4
- data.tar.gz: 612bbee201e37c8c425c5aa42bbcc6f713ca848e5cf43ad7eae5797beeefd660
3
+ metadata.gz: 0f71ead77c070efe05df2af12495ef411048fd0164655e0f1fbe11a5457b518c
4
+ data.tar.gz: 4e9a222f559e2977366ecf411f97429db22f89d1aca6b8b6de767b982594f8ce
5
5
  SHA512:
6
- metadata.gz: 7150bd10acde90cfe101845b6b6da248ae4cfb57a3742d8a33ef8d045e93d0ebfa6eaf6672376304f957206801c4f0b6ae60707d881d7621dce2d61b887405d4
7
- data.tar.gz: beb42456465d624c22fc12d2294011be076748011bfac9dfad6a6397083bcebf6902a2fd7f7fadbdfa2c8e88c2df6b862c3a1f1bff0afb3f947e45256c68cc28
6
+ metadata.gz: 406d7de1521d252c335432fa44c04fd7f3e11f0992281388d8939140ab05b5b055cb3cd5a4dc6bf30cfba15a40795f7c1f21782d989bbbebd1abeac62e5ff7fc
7
+ data.tar.gz: 9e80632bfc746766ffd6011ceb45848a2875590e29b2f9c983b4c4ed344b722c310a15a760b6d4bd99045357f9def49b08904bb53618ad0dedbf5b33c2c4cffe
@@ -1,6 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
+ class GraderRerunError < StandardError
5
+ attr_reader :run
6
+
7
+ def initialize(message, run:)
8
+ super(message)
9
+ @run = run
10
+ end
11
+ end
12
+
13
+ class GraderRerunTimeoutError < GraderRerunError; end
14
+
4
15
  # Dataset operations for the authenticated organization, reached as
5
16
  # `client.datasets`. A dataset is a named bucket of traces scoped to one
6
17
  # trace function. Experiments replay against it and its graders score its
@@ -8,7 +19,8 @@ module Bitfab
8
19
  # string keys matching the HTTP API ("traceCount", "addedTraceIds", ...).
9
20
  class Datasets
10
21
  DEFAULT_RERUN_TIMEOUT_SECONDS = 90
11
- DEFAULT_RERUN_POLL_INTERVAL_SECONDS = 1
22
+ RERUN_POLL_INTERVAL_SECONDS = 1.0
23
+ private_constant :RERUN_POLL_INTERVAL_SECONDS
12
24
  TERMINAL_RERUN_STATUSES = ["completed", "errored"].freeze
13
25
 
14
26
  def initialize(http_client)
@@ -86,22 +98,21 @@ module Bitfab
86
98
  end
87
99
 
88
100
  # Re-run graders over every trace in the dataset. Defaults to every
89
- # assigned grader, and an unassigned id is rejected. Waits for the run to
90
- # finish (up to `timeout` seconds) unless `wait:` is false, and returns the
91
- # last run state seen either way. A request matching an in-flight run
92
- # joins it.
93
- def rerun_graders(dataset_id, grader_ids: nil, wait: true,
94
- timeout: DEFAULT_RERUN_TIMEOUT_SECONDS, poll_interval: DEFAULT_RERUN_POLL_INTERVAL_SECONDS)
101
+ # assigned grader, and an unassigned id is rejected. Blocks until the run
102
+ # completes and returns it. Raises GraderRerunError when the run errors and
103
+ # GraderRerunTimeoutError when it is still going after `timeout` seconds.
104
+ # The run keeps going on Bitfab after a timeout. A request matching an
105
+ # in-flight run joins it.
106
+ def rerun_graders(dataset_id, grader_ids: nil, timeout: DEFAULT_RERUN_TIMEOUT_SECONDS)
95
107
  payload = grader_ids.nil? ? {} : {"graderIds" => grader_ids}
96
108
  started = @http_client.request(dataset_path(dataset_id, "/rerunGraders"), payload)
97
- return started unless wait
98
-
99
109
  deadline = monotonic_now + timeout
100
110
  run = started["run"]
101
111
  while !TERMINAL_RERUN_STATUSES.include?(run["status"]) && monotonic_now < deadline
102
- sleep(poll_interval)
112
+ sleep(RERUN_POLL_INTERVAL_SECONDS)
103
113
  run = get_grader_rerun(dataset_id, run_id: run["id"]) || run
104
114
  end
115
+ settle_grader_rerun(dataset_id, run, timeout)
105
116
  {"run" => run, "joinedExisting" => started["joinedExisting"]}
106
117
  end
107
118
 
@@ -114,6 +125,24 @@ module Bitfab
114
125
 
115
126
  private
116
127
 
128
+ def settle_grader_rerun(dataset_id, run, timeout)
129
+ case run["status"]
130
+ when "completed"
131
+ nil
132
+ when "errored"
133
+ raise GraderRerunError.new(
134
+ "Grader re-run on dataset #{dataset_id} errored: #{run["error"] || "no reason recorded"}",
135
+ run:
136
+ )
137
+ else
138
+ raise GraderRerunTimeoutError.new(
139
+ "Grader re-run #{run["id"]} on dataset #{dataset_id} is still #{run["status"]} after #{timeout} seconds. " \
140
+ "It keeps going on Bitfab. Read it later with get_grader_rerun(#{dataset_id.inspect}, run_id: #{run["id"].inspect}).",
141
+ run:
142
+ )
143
+ end
144
+ end
145
+
117
146
  def dataset_path(dataset_id, suffix = "")
118
147
  "/api/sdk/datasets/#{URI.encode_www_form_component(dataset_id)}#{suffix}"
119
148
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Bitfab
4
- VERSION = "0.58.4"
4
+ VERSION = "0.59.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bitfab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.58.4
4
+ version: 0.59.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Harvest Team