Skip to content

Commit 3eded0e

Browse files
committed
fix stale timestamps for checkouts
1 parent 7589927 commit 3eded0e

6 files changed

Lines changed: 19 additions & 60 deletions

File tree

app/controllers/api/v1/licenses/actions/checkouts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def checkout_license_file(**kwargs)
120120
to: :show?
121121

122122
license_file.validate!
123-
license.touch_async(:last_check_out_at,
123+
license.touch_async!(:last_check_out_at,
124124
time: Time.current,
125125
)
126126

app/controllers/api/v1/machines/actions/checkouts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def checkout_machine_file(**kwargs)
123123
to: :show?
124124

125125
machine_file.validate!
126-
machine.touch_async(:last_check_out_at,
126+
machine.touch_async!(:last_check_out_at,
127127
time: Time.current,
128128
)
129129

features/api/v1/licenses/actions/checkouts.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ Feature: License checkout actions
104104
Given time is frozen at "2022-10-16T14:52:48.000Z"
105105
And the current account is "test1"
106106
And the current account has 1 "webhook-endpoint"
107-
And the current account has 1 "license"
108-
And the last "license" has the following attributes:
107+
And the current account has 1 "license" with the following attributes:
109108
"""
110109
{ "id": "dc664944-c4e3-49a5-a3f8-a8804ffd804d" }
111110
"""

features/api/v1/machines/actions/checkouts.feature

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,7 @@ Feature: Machine checkout actions
104104
Given time is frozen at "2022-10-16T14:52:48.000Z"
105105
And the current account is "test1"
106106
And the current account has 1 "webhook-endpoint"
107-
And the current account has 1 "machine"
108-
And the last "machine" has the following attributes:
107+
And the current account has 1 "machine" with the following attributes:
109108
"""
110109
{ "id": "dc664944-c4e3-49a5-a3f8-a8804ffd804d" }
111110
"""

features/step_definitions/request_steps.rb

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@
6767
head path
6868
end
6969

70-
drain_async_create_jobs
71-
drain_async_update_jobs
70+
drain_async_jobs
7271
end
7372

7473
When /^I send a GET request to "([^\"]*)"$/ do |path|
@@ -88,8 +87,7 @@
8887
get path
8988
end
9089

91-
drain_async_create_jobs
92-
drain_async_update_jobs
90+
drain_async_jobs
9391
end
9492

9593
When /^I send a POST request to "([^\"]*)"$/ do |path|
@@ -109,8 +107,7 @@
109107
post path
110108
end
111109

112-
drain_async_create_jobs
113-
drain_async_update_jobs
110+
drain_async_jobs
114111
end
115112

116113
When /^I send a PUT request to "([^\"]*)"$/ do |path|
@@ -130,8 +127,7 @@
130127
put path
131128
end
132129

133-
drain_async_create_jobs
134-
drain_async_update_jobs
130+
drain_async_jobs
135131
end
136132

137133
When /^I send a PATCH request to "([^\"]*)"$/ do |path|
@@ -151,8 +147,7 @@
151147
patch path
152148
end
153149

154-
drain_async_create_jobs
155-
drain_async_update_jobs
150+
drain_async_jobs
156151
end
157152

158153
When /^I send a POST request to "([^\"]*)" with the following:$/ do |path, body|
@@ -173,8 +168,7 @@
173168
post path, body
174169
end
175170

176-
drain_async_create_jobs
177-
drain_async_update_jobs
171+
drain_async_jobs
178172
end
179173

180174
When /^I send a POST request to "([^\"]*)" with the following badly encoded data:$/ do |path, body|
@@ -195,8 +189,7 @@
195189
post path, body.encode!('CP1252')
196190
end
197191

198-
drain_async_create_jobs
199-
drain_async_update_jobs
192+
drain_async_jobs
200193
end
201194

202195
When /^I send a PATCH request to "([^\"]*)" with the following:$/ do |path, body|
@@ -217,8 +210,7 @@
217210
patch path, body
218211
end
219212

220-
drain_async_create_jobs
221-
drain_async_update_jobs
213+
drain_async_jobs
222214
end
223215

224216
When /^I send a PUT request to "([^\"]*)" with the following:$/ do |path, body|
@@ -239,8 +231,7 @@
239231
put path, body
240232
end
241233

242-
drain_async_create_jobs
243-
drain_async_update_jobs
234+
drain_async_jobs
244235
end
245236

246237
When /^I send a DELETE request to "([^\"]*)" with the following:$/ do |path, body|
@@ -261,9 +252,7 @@
261252
delete path, body
262253
end
263254

264-
drain_async_create_jobs
265-
drain_async_update_jobs
266-
drain_async_destroy_jobs
255+
drain_async_jobs
267256
end
268257

269258
When /^I send a DELETE request to "([^\"]*)"$/ do |path|
@@ -283,9 +272,7 @@
283272
delete path
284273
end
285274

286-
drain_async_create_jobs
287-
drain_async_update_jobs
288-
drain_async_destroy_jobs
275+
drain_async_jobs
289276
rescue Timeout::Error
290277
end
291278

features/step_definitions/worker_steps.rb

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,15 @@
22

33
World Rack::Test::Methods
44

5-
def drain_async_destroy_jobs
5+
def drain_async_jobs
66
require 'sidekiq/testing'
77

8-
# FIXME(ezekg) We only want to process the destroy async jobs so we
9-
# can't just drain the entire job wrapper class.
8+
# FIXME(ezekg) there doesn't seem to be an easier way to drain a subset of wrapped jobs
109
active_job = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
1110
active_job.jobs.each do |job|
1211
case job['wrapped']
13-
when ActiveRecord::DestroyAssociationAsyncJob.name
14-
active_job.process_job(job)
15-
end
16-
end
17-
18-
YankArtifactWorker.drain
19-
end
20-
21-
def drain_async_create_jobs
22-
require 'sidekiq/testing'
23-
24-
active_job = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
25-
active_job.jobs.each do |job|
26-
case job['wrapped']
27-
when AsyncCreatable::CreateAsyncJob.name
28-
active_job.process_job(job)
29-
end
30-
end
31-
end
32-
33-
def drain_async_update_jobs
34-
require 'sidekiq/testing'
35-
36-
active_job = ActiveJob::QueueAdapters::SidekiqAdapter::JobWrapper
37-
active_job.jobs.each do |job|
38-
case job['wrapped']
39-
when AsyncUpdatable::UpdateAsyncJob.name
12+
when AsyncCreatable::CreateAsyncJob.name, AsyncUpdatable::UpdateAsyncJob.name,
13+
AsyncTouchable::TouchAsyncJob.name, AsyncDestroyable::DestroyAsyncJob.name
4014
active_job.process_job(job)
4115
end
4216
end

0 commit comments

Comments
 (0)