Skip to content

Commit d4975ac

Browse files
authored
Revert "Add graph-level webhooks for execution failure and completion (#607)" (#738)
This reverts commit 1a6be3f.
1 parent 1a6be3f commit d4975ac

5 files changed

Lines changed: 32 additions & 137 deletions

File tree

state-manager/app/controller/errored_state.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@
99
from app.models.state_status_enum import StateStatusEnum
1010
from app.singletons.logs_manager import LogsManager
1111
from app.models.db.graph_template_model import GraphTemplate
12-
from app.tasks.webhook import dispatch_webhook
13-
from datetime import datetime
14-
from fastapi import BackgroundTasks
1512

1613
logger = LogsManager().get_logger()
17-
async def errored_state(namespace_name: str, state_id: PydanticObjectId, body: ErroredRequestModel, x_exosphere_request_id: str, background_tasks: BackgroundTasks | None = None,) -> ErroredResponseModel:
18-
if background_tasks is None:
19-
background_tasks = BackgroundTasks()
14+
15+
async def errored_state(namespace_name: str, state_id: PydanticObjectId, body: ErroredRequestModel, x_exosphere_request_id: str) -> ErroredResponseModel:
16+
2017
try:
2118
logger.info(f"Errored state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id)
2219

@@ -73,26 +70,6 @@ async def errored_state(namespace_name: str, state_id: PydanticObjectId, body: E
7370
state.error = body.error
7471
await state.save()
7572

76-
if (
77-
not retry_created
78-
and graph_template.webhook
79-
and "GRAPH_FAILED" in graph_template.webhook.events
80-
):
81-
background_tasks.add_task(
82-
dispatch_webhook,
83-
url=graph_template.webhook.url,
84-
payload={
85-
"event": "GRAPH_FAILED",
86-
"namespace": namespace_name,
87-
"graph_name": state.graph_name,
88-
"run_id": state.run_id,
89-
"failed_state_id": str(state.id),
90-
"node_name": state.node_name,
91-
"error": body.error,
92-
"timestamp": datetime.utcnow().isoformat(),
93-
},
94-
headers=graph_template.webhook.headers,
95-
)
9673
return ErroredResponseModel(status=StateStatusEnum.ERRORED, retry_created=retry_created)
9774

9875
except Exception as e:
Lines changed: 28 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,101 +1,64 @@
11
from beanie import PydanticObjectId
2+
from app.models.executed_models import ExecutedRequestModel, ExecutedResponseModel
3+
24
from fastapi import HTTPException, status, BackgroundTasks
35

4-
from app.models.executed_models import ExecutedRequestModel, ExecutedResponseModel
56
from app.models.db.state import State
67
from app.models.state_status_enum import StateStatusEnum
78
from app.singletons.logs_manager import LogsManager
89
from app.tasks.create_next_states import create_next_states
910

1011
logger = LogsManager().get_logger()
1112

13+
async def executed_state(namespace_name: str, state_id: PydanticObjectId, body: ExecutedRequestModel, x_exosphere_request_id: str, background_tasks: BackgroundTasks) -> ExecutedResponseModel:
1214

13-
async def executed_state(
14-
namespace_name: str,
15-
state_id: PydanticObjectId,
16-
body: ExecutedRequestModel,
17-
x_exosphere_request_id: str,
18-
background_tasks: BackgroundTasks,
19-
) -> ExecutedResponseModel:
2015
try:
21-
logger.info(
22-
f"Executed state {state_id} for namespace {namespace_name}",
23-
x_exosphere_request_id=x_exosphere_request_id,
24-
)
16+
logger.info(f"Executed state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id)
2517

2618
state = await State.find_one(State.id == state_id)
2719
if not state or not state.id:
28-
raise HTTPException(
29-
status_code=status.HTTP_404_NOT_FOUND,
30-
detail="State not found",
31-
)
20+
raise HTTPException(status_code=status.HTTP_404_NOT_FOUND, detail="State not found")
3221

3322
if state.status != StateStatusEnum.QUEUED:
34-
raise HTTPException(
35-
status_code=status.HTTP_400_BAD_REQUEST,
36-
detail="State is not queued",
37-
)
38-
39-
next_state_ids: list[PydanticObjectId] = []
40-
41-
# ---- Handle outputs ----
23+
raise HTTPException(status_code=status.HTTP_400_BAD_REQUEST, detail="State is not queued")
24+
25+
next_state_ids = []
4226
if len(body.outputs) == 0:
4327
state.status = StateStatusEnum.EXECUTED
4428
state.outputs = {}
4529
await state.save()
4630

4731
next_state_ids.append(state.id)
4832

49-
else:
50-
# First output updates the current state
33+
else:
5134
state.outputs = body.outputs[0]
5235
state.status = StateStatusEnum.EXECUTED
5336
await state.save()
54-
5537
next_state_ids.append(state.id)
5638

57-
# Remaining outputs create new states
5839
new_states = []
5940
for output in body.outputs[1:]:
60-
new_states.append(
61-
State(
62-
node_name=state.node_name,
63-
namespace_name=state.namespace_name,
64-
identifier=state.identifier,
65-
graph_name=state.graph_name,
66-
run_id=state.run_id,
67-
status=StateStatusEnum.EXECUTED,
68-
inputs=state.inputs,
69-
outputs=output,
70-
error=None,
71-
parents=state.parents,
72-
)
73-
)
74-
75-
if new_states:
76-
inserted_ids = (
77-
await State.insert_many(new_states)
78-
).inserted_ids
41+
new_states.append(State(
42+
node_name=state.node_name,
43+
namespace_name=state.namespace_name,
44+
identifier=state.identifier,
45+
graph_name=state.graph_name,
46+
run_id=state.run_id,
47+
status=StateStatusEnum.EXECUTED,
48+
inputs=state.inputs,
49+
outputs=output,
50+
error=None,
51+
parents=state.parents
52+
))
53+
54+
if len(new_states) > 0:
55+
inserted_ids = (await State.insert_many(new_states)).inserted_ids
7956
next_state_ids.extend(inserted_ids)
8057

81-
# ---- Create next states ----
82-
background_tasks.add_task(
83-
create_next_states,
84-
next_state_ids,
85-
state.identifier,
86-
state.namespace_name,
87-
state.graph_name,
88-
state.parents,
89-
)
58+
background_tasks.add_task(create_next_states, next_state_ids, state.identifier, state.namespace_name, state.graph_name, state.parents)
9059

91-
return ExecutedResponseModel(
92-
status=StateStatusEnum.EXECUTED
93-
)
60+
return ExecutedResponseModel(status=StateStatusEnum.EXECUTED)
9461

9562
except Exception as e:
96-
logger.error(
97-
f"Error executing state {state_id} for namespace {namespace_name}",
98-
x_exosphere_request_id=x_exosphere_request_id,
99-
error=e,
100-
)
101-
raise
63+
logger.error(f"Error executing state {state_id} for namespace {namespace_name}", x_exosphere_request_id=x_exosphere_request_id, error=e)
64+
raise e

state-manager/app/models/db/graph_template_model.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from app.models.retry_policy_model import RetryPolicyModel
1515
from app.models.store_config_model import StoreConfig
1616
from app.models.trigger_models import Trigger
17-
from app.models.webhook_config_model import WebhookConfig
1817

1918
class GraphTemplate(BaseDatabaseModel):
2019
name: str = Field(..., description="Name of the graph")
@@ -26,7 +25,6 @@ class GraphTemplate(BaseDatabaseModel):
2625
triggers: List[Trigger] = Field(default_factory=list, description="Triggers of the graph")
2726
retry_policy: RetryPolicyModel = Field(default_factory=RetryPolicyModel, description="Retry policy of the graph")
2827
store_config: StoreConfig = Field(default_factory=StoreConfig, description="Store config of the graph")
29-
webhook: WebhookConfig | None = Field(default=None, description="Optional webhook configuration for graph execution events")
3028

3129
_node_by_identifier: Dict[str, NodeTemplate] | None = PrivateAttr(default=None)
3230
_parents_by_identifier: Dict[str, set[str]] | None = PrivateAttr(default=None) # type: ignore
@@ -320,7 +318,7 @@ def get_path_by_identifier(self, identifier: str) -> set[str]:
320318

321319
@staticmethod
322320
async def get(namespace: str, graph_name: str) -> "GraphTemplate":
323-
graph_template = await GraphTemplate.find_one(GraphTemplate.namespace == namespace,GraphTemplate.name == graph_name)
321+
graph_template = await GraphTemplate.find_one(GraphTemplate.namespace == namespace, GraphTemplate.name == graph_name)
324322
if not graph_template:
325323
raise ValueError(f"Graph template not found for namespace: {namespace} and graph name: {graph_name}")
326324
return graph_template

state-manager/app/models/webhook_config_model.py

Lines changed: 0 additions & 11 deletions
This file was deleted.

state-manager/app/tasks/webhook.py

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)