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')
|
||||
|
||||
+23
-1
@@ -72,6 +72,8 @@ Rails の既存 Active Job と `:async` adapter を使い、生成は HTTP reque
|
||||
進まない queued / running は75秒経過後の状態取得又は次の受付で failed になる。
|
||||
worker は受付中の短い実行ロック競合を待ち、競合だけを理由に queued を放棄しない。
|
||||
再開や再実行はしない。実行ロック待ちも登録からの60秒の処理期限に含まれる。
|
||||
停滞検知で failed になったジョブは、遅れた worker の進捗・完了・例外処理から
|
||||
書き換えない。queued の読み取り直後に停滞判定された場合も、生成を開始しない。
|
||||
|
||||
失敗コードは `too_large`、`generation_timeout`、`publication_changed`、
|
||||
`generation_failed`、`worker_stopped`。内部の例外本文・パス・資源属性は応答に含めない。
|
||||
@@ -191,7 +193,27 @@ rate limit、容量・時間・負荷の実測、公開制御の監査と変更
|
||||
asset の権利・保管方針、追加 resource の安全な投影、UI 文言・翻訳の確定が必要。
|
||||
本 PoC の開発環境制限を単に外して公開することは想定しない。
|
||||
|
||||
## 今回のレビュー対応の変更ファイル
|
||||
## 追加点検での変更ファイル
|
||||
|
||||
レビュー5点の既存実装を確認し、その実装を維持した。追加修正は単一生成枠の状態遷移に
|
||||
限定した。従来の `update` は ID の一致だけを確認していたため、状態取得又は次の受付が
|
||||
停滞ジョブを failed にした後も、worker が running / ready へ戻す競合が残っていた。
|
||||
registry lock の中で failed 状態の更新を拒否し、生成開始の更新を拒否された worker は
|
||||
そのまま終了する。生成中に停滞判定された場合も、進捗・完了・失敗理由の上書きを防ぐ。
|
||||
|
||||
| ファイル | 修正と理由 |
|
||||
| --- | --- |
|
||||
| `backend/app/jobs/static_mirror_job.rb` | failed への遷移を worker が取り消さないよう、更新と生成開始を制限 |
|
||||
| `backend/spec/requests/static_mirrors_spec.rb` | queued 読取直後の停滞検知、running 失効後の進捗・完了と ZIP 取得拒否を検証する2ケースを追加 |
|
||||
| `docs/static-mirror.md` | 今回の競合修正と未検証範囲を記録 |
|
||||
|
||||
新規回帰テストは、状態取得と worker 更新の順番を制御して競合を再現する。
|
||||
テスト・lint・build・migration、DB 接続、実ブラウザー・ZIP 配置確認は実行していない。
|
||||
非永続キュー、ロック取得自体の無期限待ち、厳密な DB read view 成立時刻の取得、
|
||||
過去時点復元、本番公開に必要な検証と運用設計は未解決のまま。
|
||||
公開契約・検索・本家リンク・`data_at` の意味及び機能範囲に追加変更はない。
|
||||
|
||||
## 前回までのレビュー対応の変更ファイル
|
||||
|
||||
| ファイル | 修正と理由 |
|
||||
| --- | --- |
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする