Skip to content

Commit 433c997

Browse files
authored
Adding compatibility tests for client and server triggers and actions (#12778)
1 parent 7e73539 commit 433c997

File tree

3 files changed

+386
-4
lines changed

3 files changed

+386
-4
lines changed

src/prefect/events/__init__.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Automation,
55
AutomationCore,
66
Posture,
7+
TriggerTypes,
78
Trigger,
89
ResourceTrigger,
910
EventTrigger,
@@ -21,6 +22,26 @@
2122
DeploymentCompoundTrigger,
2223
DeploymentSequenceTrigger,
2324
)
25+
from .actions import (
26+
ActionTypes,
27+
Action,
28+
DoNothing,
29+
RunDeployment,
30+
PauseDeployment,
31+
ResumeDeployment,
32+
ChangeFlowRunState,
33+
CancelFlowRun,
34+
SuspendFlowRun,
35+
CallWebhook,
36+
SendNotification,
37+
PauseWorkPool,
38+
ResumeWorkPool,
39+
PauseWorkQueue,
40+
ResumeWorkQueue,
41+
PauseAutomation,
42+
ResumeAutomation,
43+
DeclareIncident,
44+
)
2445
from .clients import get_events_client, get_events_subscriber
2546
from .utilities import emit_event
2647

@@ -33,6 +54,7 @@
3354
"Automation",
3455
"AutomationCore",
3556
"Posture",
57+
"TriggerTypes",
3658
"Trigger",
3759
"ResourceTrigger",
3860
"EventTrigger",
@@ -47,6 +69,24 @@
4769
"DeploymentMetricTrigger",
4870
"DeploymentCompoundTrigger",
4971
"DeploymentSequenceTrigger",
72+
"ActionTypes",
73+
"Action",
74+
"DoNothing",
75+
"RunDeployment",
76+
"PauseDeployment",
77+
"ResumeDeployment",
78+
"ChangeFlowRunState",
79+
"CancelFlowRun",
80+
"SuspendFlowRun",
81+
"CallWebhook",
82+
"SendNotification",
83+
"PauseWorkPool",
84+
"ResumeWorkPool",
85+
"PauseWorkQueue",
86+
"ResumeWorkQueue",
87+
"PauseAutomation",
88+
"ResumeAutomation",
89+
"DeclareIncident",
5090
"emit_event",
5191
"get_events_client",
5292
"get_events_subscriber",

src/prefect/events/schemas/deployment_triggers.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ class DeploymentEventTrigger(DeploymentResourceTrigger):
146146
period of time.
147147
"""
148148

149+
trigger_type = EventTrigger
150+
149151
type: Literal["event"] = "event"
150152

151153
after: Set[str] = Field(
@@ -226,7 +228,7 @@ def enforce_minimum_within_for_proactive_triggers(cls, values: Dict[str, Any]):
226228
return values
227229

228230
def as_trigger(self) -> Trigger:
229-
return EventTrigger(
231+
return self.trigger_type(
230232
match=self.match,
231233
match_related=self.match_related,
232234
after=self.after,
@@ -243,6 +245,8 @@ class DeploymentMetricTrigger(DeploymentResourceTrigger):
243245
A trigger that fires based on the results of a metric query.
244246
"""
245247

248+
trigger_type = MetricTrigger
249+
246250
type: Literal["metric"] = "metric"
247251

248252
posture: Literal[Posture.Metric] = Field( # type: ignore[valid-type]
@@ -256,7 +260,7 @@ class DeploymentMetricTrigger(DeploymentResourceTrigger):
256260
)
257261

258262
def as_trigger(self) -> Trigger:
259-
return MetricTrigger(
263+
return self.trigger_type(
260264
match=self.match,
261265
match_related=self.match_related,
262266
posture=self.posture,
@@ -279,6 +283,8 @@ class DeploymentCompoundTrigger(DeploymentCompositeTrigger):
279283
"""A composite trigger that requires some number of triggers to have
280284
fired within the given time period"""
281285

286+
trigger_type = CompoundTrigger
287+
282288
type: Literal["compound"] = "compound"
283289
require: Union[int, Literal["any", "all"]]
284290

@@ -297,7 +303,7 @@ def validate_require(cls, values: Dict[str, Any]) -> Dict[str, Any]:
297303
return values
298304

299305
def as_trigger(self) -> Trigger:
300-
return CompoundTrigger(
306+
return self.trigger_type(
301307
require=self.require,
302308
triggers=self.triggers,
303309
within=self.within,
@@ -309,10 +315,12 @@ class DeploymentSequenceTrigger(DeploymentCompositeTrigger):
309315
"""A composite trigger that requires some number of triggers to have fired
310316
within the given time period in a specific order"""
311317

318+
trigger_type = SequenceTrigger
319+
312320
type: Literal["sequence"] = "sequence"
313321

314322
def as_trigger(self) -> Trigger:
315-
return SequenceTrigger(
323+
return self.trigger_type(
316324
triggers=self.triggers,
317325
within=self.within,
318326
job_variables=self.job_variables,

0 commit comments

Comments
 (0)