AI: address issue #483
このコミットが含まれているのは:
@@ -108,9 +108,12 @@ class StaticMirrorJob < ApplicationJob
|
||||
synchronise(blocking: true) do
|
||||
value = state
|
||||
return unless value && value['id'] == id
|
||||
# Expiry is terminal even when a delayed worker still owns the generation lock.
|
||||
return if value['status'] == 'failed'
|
||||
|
||||
yield value
|
||||
write(value)
|
||||
value
|
||||
end
|
||||
end
|
||||
|
||||
@@ -129,7 +132,7 @@ class StaticMirrorJob < ApplicationJob
|
||||
private
|
||||
|
||||
def generate(id, value)
|
||||
self.class.update(id) { _1['status'] = 'running' }
|
||||
return unless self.class.update(id) { _1['status'] = 'running' }
|
||||
remaining = MAX_SECONDS - (Time.current.to_f - value.fetch('created_at'))
|
||||
raise Timeout::Error unless remaining.positive?
|
||||
|
||||
|
||||
@@ -210,6 +210,39 @@ RSpec.describe 'Static Mirror API', type: :request do
|
||||
lock&.close
|
||||
end
|
||||
|
||||
it 'preserves expiry between reading the queue and starting generation' do
|
||||
id = create_job
|
||||
worker = StaticMirrorJob.new
|
||||
allow(worker).to receive(:generate).and_wrap_original do |original, *arguments|
|
||||
travel 80.seconds do
|
||||
get "/static_mirror/jobs/#{ id }"
|
||||
expect(json).to include('status' => 'failed', 'error' => 'worker_stopped')
|
||||
original.call(*arguments)
|
||||
end
|
||||
end
|
||||
worker.perform(id)
|
||||
expect(StaticMirrorJob.state).to include('status' => 'failed', 'error' => 'worker_stopped')
|
||||
end
|
||||
|
||||
it 'rejects late progress and completion after a running job expires' do
|
||||
id = create_job
|
||||
mirror = instance_double(StaticMirror, data_at: Time.current.utc.iso8601(6), authority: { })
|
||||
allow(StaticMirror).to receive(:new).and_return(mirror)
|
||||
allow(mirror).to receive(:export) do |&progress|
|
||||
travel 80.seconds do
|
||||
get "/static_mirror/jobs/#{ id }"
|
||||
expect(json).to include('status' => 'failed', 'error' => 'worker_stopped')
|
||||
progress.call(1, 1)
|
||||
end
|
||||
'late archive bytes'
|
||||
end
|
||||
StaticMirrorJob.perform_now(id)
|
||||
expect(StaticMirrorJob.state).to include('status' => 'failed', 'error' => 'worker_stopped',
|
||||
'processed' => 0, 'total' => nil)
|
||||
get "/static_mirror/files/#{ id }"
|
||||
expect(response).to have_http_status(:not_found)
|
||||
end
|
||||
|
||||
it 'reports bounded-generation failures without returning internal exception messages' do
|
||||
id = create_job
|
||||
allow(StaticMirror).to receive(:new).and_raise(StaticMirror::TooLarge, 'private details')
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする