Skip to content
Merged

BE/FE #285

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions backend/app/services/tasks/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,14 @@ def _finalize_completed(task_type: TaskType, user_id) -> None:
def _finalize_dead_letter(
task_type: TaskType, payload: dict, user_id, *, error: Exception
) -> None:
"""終端ステータス(dead_letter)への更新と失敗通知をまとめて行う。"""
"""終端ステータス(dead_letter)への更新と失敗通知を行う。

def work(db: Session) -> None:
_mark_dead_letter(db, task_type, payload, error=error)
_notify_if_real_user(db, task_type, user_id, "failed")

_run_in_new_session(work)
``_mark_dead_letter`` は DB エラーを握りつぶす(rollback しない)ため、commit 失敗時に
セッションが失効状態のまま残りうる。通知作成が汚染セッションを再利用しないよう、
状態更新と通知はそれぞれ独立した新規セッションで実行する。
"""
_run_in_new_session(lambda db: _mark_dead_letter(db, task_type, payload, error=error))
_run_in_new_session(lambda db: _notify_if_real_user(db, task_type, user_id, "failed"))


def _finalize_retrying(
Expand Down
2 changes: 2 additions & 0 deletions backend/tests/test_worker/test_github_link.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ def test_contribution_calendar_persisted_in_result(

db_session.refresh(cache)
assert cache.status == "completed"
assert cache.result is not None
assert cache.result["contribution_calendar"]["total_contributions"] == 7
assert cache.result["contribution_calendar"]["weeks"][0][0]["level"] == 2
assert cache.warning_message is None
Expand Down Expand Up @@ -242,6 +243,7 @@ def test_contribution_fetch_failure_sets_warning(

db_session.refresh(cache)
assert cache.status == "completed"
assert cache.result is not None
assert cache.result["contribution_calendar"] is None
assert cache.warning_message is not None

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ export function ClientEditor({
className="danger"
onClick={() => onRemoveClient(expIndex, clientIndex)}
>
取引先を削除
{client.is_vacation ? "休業を削除" : "取引先を削除"}
</button>
</div>
);
Expand Down
Loading