mirror of
https://github.com/Significant-Gravitas/AutoGPT.git
synced 2026-02-02 19:05:10 -05:00
Compare commits
2 Commits
ntindle/fi
...
fix/schedu
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b1f0df58c | ||
|
|
1081590384 |
@@ -193,9 +193,11 @@ async def _handle_graph_validation_error(args: "GraphExecutionJobArgs") -> None:
|
||||
user_id=args.user_id,
|
||||
)
|
||||
else:
|
||||
logger.error(
|
||||
f"Unable to unschedule graph: {args.graph_id} as this is an old job with no associated schedule_id please remove manually"
|
||||
logger.warning(
|
||||
f"Old scheduled job for graph {args.graph_id} (user {args.user_id}) "
|
||||
f"has no schedule_id, attempting targeted cleanup"
|
||||
)
|
||||
await _cleanup_old_schedules_without_id(args.graph_id, args.user_id)
|
||||
|
||||
|
||||
async def _handle_graph_not_available(
|
||||
@@ -238,6 +240,35 @@ async def _cleanup_orphaned_schedules_for_graph(graph_id: str, user_id: str) ->
|
||||
)
|
||||
|
||||
|
||||
async def _cleanup_old_schedules_without_id(graph_id: str, user_id: str) -> None:
|
||||
"""Remove only schedules that have no schedule_id in their job args.
|
||||
|
||||
Unlike _cleanup_orphaned_schedules_for_graph (which removes ALL schedules
|
||||
for a graph), this only targets legacy jobs created before schedule_id was
|
||||
added to GraphExecutionJobArgs, preserving any valid newer schedules.
|
||||
"""
|
||||
scheduler_client = get_scheduler_client()
|
||||
schedules = await scheduler_client.get_execution_schedules(
|
||||
graph_id=graph_id, user_id=user_id
|
||||
)
|
||||
|
||||
for schedule in schedules:
|
||||
if schedule.schedule_id is not None:
|
||||
continue
|
||||
try:
|
||||
await scheduler_client.delete_schedule(
|
||||
schedule_id=schedule.id, user_id=user_id
|
||||
)
|
||||
logger.info(
|
||||
f"Cleaned up old schedule {schedule.id} (no schedule_id) "
|
||||
f"for graph {graph_id}"
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
f"Failed to delete old schedule {schedule.id} for graph {graph_id}"
|
||||
)
|
||||
|
||||
|
||||
def cleanup_expired_files():
|
||||
"""Clean up expired files from cloud storage."""
|
||||
# Wait for completion
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
from urllib.parse import urlparse
|
||||
|
||||
import fastapi
|
||||
from fastapi.routing import APIRoute
|
||||
|
||||
from backend.api.features.integrations.router import router as integrations_router
|
||||
from backend.integrations.providers import ProviderName
|
||||
from backend.integrations.webhooks import utils as webhooks_utils
|
||||
|
||||
|
||||
def test_webhook_ingress_url_matches_route(monkeypatch) -> None:
|
||||
app = fastapi.FastAPI()
|
||||
app.include_router(integrations_router, prefix="/api/integrations")
|
||||
|
||||
provider = ProviderName.GITHUB
|
||||
webhook_id = "webhook_123"
|
||||
base_url = "https://example.com"
|
||||
|
||||
monkeypatch.setattr(webhooks_utils.app_config, "platform_base_url", base_url)
|
||||
|
||||
route = next(
|
||||
route
|
||||
for route in integrations_router.routes
|
||||
if isinstance(route, APIRoute)
|
||||
and route.path == "/{provider}/webhooks/{webhook_id}/ingress"
|
||||
and "POST" in route.methods
|
||||
)
|
||||
expected_path = f"/api/integrations{route.path}".format(
|
||||
provider=provider.value,
|
||||
webhook_id=webhook_id,
|
||||
)
|
||||
actual_url = urlparse(webhooks_utils.webhook_ingress_url(provider, webhook_id))
|
||||
expected_base = urlparse(base_url)
|
||||
|
||||
assert (actual_url.scheme, actual_url.netloc) == (
|
||||
expected_base.scheme,
|
||||
expected_base.netloc,
|
||||
)
|
||||
assert actual_url.path == expected_path
|
||||
Reference in New Issue
Block a user