mirror of
https://github.com/langgenius/dify.git
synced 2026-04-29 04:26:30 +08:00
[autofix.ci] apply automated fixes
This commit is contained in:
parent
d8578dd4ba
commit
66ee07154d
@ -114,9 +114,7 @@ class WorkflowRunCleanup:
|
|||||||
|
|
||||||
click.echo(click.style(summary_message, fg="white"))
|
click.echo(click.style(summary_message, fg="white"))
|
||||||
|
|
||||||
def _load_batch(
|
def _load_batch(self, session: Session, last_seen: tuple[datetime.datetime, str] | None) -> list[WorkflowRunRow]:
|
||||||
self, session: Session, last_seen: tuple[datetime.datetime, str] | None
|
|
||||||
) -> list[WorkflowRunRow]:
|
|
||||||
stmt = (
|
stmt = (
|
||||||
select(WorkflowRun.id, WorkflowRun.tenant_id, WorkflowRun.created_at)
|
select(WorkflowRun.id, WorkflowRun.tenant_id, WorkflowRun.created_at)
|
||||||
.where(WorkflowRun.created_at < self.window_end)
|
.where(WorkflowRun.created_at < self.window_end)
|
||||||
@ -166,7 +164,9 @@ class WorkflowRunCleanup:
|
|||||||
|
|
||||||
def _delete_runs(self, session: Session, workflow_run_ids: Sequence[str]) -> dict[str, int]:
|
def _delete_runs(self, session: Session, workflow_run_ids: Sequence[str]) -> dict[str, int]:
|
||||||
node_execution_ids = session.scalars(
|
node_execution_ids = session.scalars(
|
||||||
select(WorkflowNodeExecutionModel.id).where(WorkflowNodeExecutionModel.workflow_run_id.in_(workflow_run_ids))
|
select(WorkflowNodeExecutionModel.id).where(
|
||||||
|
WorkflowNodeExecutionModel.workflow_run_id.in_(workflow_run_ids)
|
||||||
|
)
|
||||||
).all()
|
).all()
|
||||||
|
|
||||||
offloads_deleted = 0
|
offloads_deleted = 0
|
||||||
@ -199,14 +199,12 @@ class WorkflowRunCleanup:
|
|||||||
|
|
||||||
if pause_ids:
|
if pause_ids:
|
||||||
pause_reasons_deleted = (
|
pause_reasons_deleted = (
|
||||||
session.query(WorkflowPauseReason).where(WorkflowPauseReason.pause_id.in_(pause_ids)).delete(
|
session.query(WorkflowPauseReason)
|
||||||
synchronize_session=False
|
.where(WorkflowPauseReason.pause_id.in_(pause_ids))
|
||||||
)
|
.delete(synchronize_session=False)
|
||||||
)
|
)
|
||||||
pauses_deleted = (
|
pauses_deleted = (
|
||||||
session.query(WorkflowPause)
|
session.query(WorkflowPause).where(WorkflowPause.id.in_(pause_ids)).delete(synchronize_session=False)
|
||||||
.where(WorkflowPause.id.in_(pause_ids))
|
|
||||||
.delete(synchronize_session=False)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
trigger_logs_deleted = (
|
trigger_logs_deleted = (
|
||||||
|
|||||||
@ -85,9 +85,7 @@ def test_run_deletes_only_free_tenants(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
|
|
||||||
batches_returned = 0
|
batches_returned = 0
|
||||||
|
|
||||||
def fake_load_batch(
|
def fake_load_batch(session: DummySession, last_seen: tuple[datetime.datetime, str] | None) -> list[WorkflowRunRow]:
|
||||||
session: DummySession, last_seen: tuple[datetime.datetime, str] | None
|
|
||||||
) -> list[WorkflowRunRow]:
|
|
||||||
nonlocal batches_returned
|
nonlocal batches_returned
|
||||||
if batches_returned > 0:
|
if batches_returned > 0:
|
||||||
return []
|
return []
|
||||||
@ -130,7 +128,7 @@ def test_run_deletes_only_free_tenants(monkeypatch: pytest.MonkeyPatch) -> None:
|
|||||||
cleanup.run()
|
cleanup.run()
|
||||||
|
|
||||||
assert deleted_ids == [["run-free"]]
|
assert deleted_ids == [["run-free"]]
|
||||||
assert created_sessions
|
assert created_sessions
|
||||||
assert created_sessions[0].committed is True
|
assert created_sessions[0].committed is True
|
||||||
|
|
||||||
|
|
||||||
@ -142,16 +140,12 @@ def test_run_skips_when_no_free_tenants(monkeypatch: pytest.MonkeyPatch) -> None
|
|||||||
monkeypatch.setattr(
|
monkeypatch.setattr(
|
||||||
cleanup_module.BillingService,
|
cleanup_module.BillingService,
|
||||||
"get_info_bulk",
|
"get_info_bulk",
|
||||||
staticmethod(
|
staticmethod(lambda tenant_ids: {tenant_id: {"subscription": {"plan": "TEAM"}} for tenant_id in tenant_ids}),
|
||||||
lambda tenant_ids: {tenant_id: {"subscription": {"plan": "TEAM"}} for tenant_id in tenant_ids}
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
batches_returned = 0
|
batches_returned = 0
|
||||||
|
|
||||||
def fake_load_batch(
|
def fake_load_batch(session: DummySession, last_seen: tuple[datetime.datetime, str] | None) -> list[WorkflowRunRow]:
|
||||||
session: DummySession, last_seen: tuple[datetime.datetime, str] | None
|
|
||||||
) -> list[WorkflowRunRow]:
|
|
||||||
nonlocal batches_returned
|
nonlocal batches_returned
|
||||||
if batches_returned > 0:
|
if batches_returned > 0:
|
||||||
return []
|
return []
|
||||||
@ -164,14 +158,14 @@ def test_run_skips_when_no_free_tenants(monkeypatch: pytest.MonkeyPatch) -> None
|
|||||||
nonlocal delete_called
|
nonlocal delete_called
|
||||||
delete_called = True
|
delete_called = True
|
||||||
return {
|
return {
|
||||||
"runs": 0,
|
"runs": 0,
|
||||||
"node_executions": 0,
|
"node_executions": 0,
|
||||||
"offloads": 0,
|
"offloads": 0,
|
||||||
"app_logs": 0,
|
"app_logs": 0,
|
||||||
"trigger_logs": 0,
|
"trigger_logs": 0,
|
||||||
"pauses": 0,
|
"pauses": 0,
|
||||||
"pause_reasons": 0
|
"pause_reasons": 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
def fake_session_factory(engine: object | None = None) -> DummySession: # pragma: no cover - simple factory
|
def fake_session_factory(engine: object | None = None) -> DummySession: # pragma: no cover - simple factory
|
||||||
return DummySession()
|
return DummySession()
|
||||||
@ -189,9 +183,7 @@ def test_run_skips_when_no_free_tenants(monkeypatch: pytest.MonkeyPatch) -> None
|
|||||||
def test_run_exits_on_empty_batch(monkeypatch: pytest.MonkeyPatch) -> None:
|
def test_run_exits_on_empty_batch(monkeypatch: pytest.MonkeyPatch) -> None:
|
||||||
cleanup = WorkflowRunCleanup(days=30, batch_size=10)
|
cleanup = WorkflowRunCleanup(days=30, batch_size=10)
|
||||||
|
|
||||||
def fake_load_batch(
|
def fake_load_batch(session: DummySession, last_seen: tuple[datetime.datetime, str] | None) -> list[WorkflowRunRow]:
|
||||||
session: DummySession, last_seen: tuple[datetime.datetime, str] | None
|
|
||||||
) -> list[WorkflowRunRow]:
|
|
||||||
return []
|
return []
|
||||||
|
|
||||||
def fake_delete_runs(session: DummySession, workflow_run_ids: list[str]) -> dict[str, int]:
|
def fake_delete_runs(session: DummySession, workflow_run_ids: list[str]) -> dict[str, int]:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user