Skip to content

Commit f3d068a

Browse files
authored
Run plugins in executor (#2701)
1 parent 3caddcb commit f3d068a

File tree

5 files changed

+9
-8
lines changed

5 files changed

+9
-8
lines changed

src/dstack/_internal/server/services/fleets.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ async def get_plan(
237237
) -> FleetPlan:
238238
# Spec must be copied by parsing to calculate merged_profile
239239
effective_spec = FleetSpec.parse_obj(spec.dict())
240-
effective_spec = apply_plugin_policies(
240+
effective_spec = await apply_plugin_policies(
241241
user=user.name,
242242
project=project.name,
243243
spec=effective_spec,
@@ -342,7 +342,7 @@ async def create_fleet(
342342
spec: FleetSpec,
343343
) -> Fleet:
344344
# Spec must be copied by parsing to calculate merged_profile
345-
spec = apply_plugin_policies(
345+
spec = await apply_plugin_policies(
346346
user=user.name,
347347
project=project.name,
348348
spec=spec,

src/dstack/_internal/server/services/gateways/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ async def create_gateway(
140140
project: ProjectModel,
141141
configuration: GatewayConfiguration,
142142
) -> Gateway:
143-
spec = apply_plugin_policies(
143+
spec = await apply_plugin_policies(
144144
user=user.name,
145145
project=project.name,
146146
# Create pseudo spec until the gateway API is updated to accept spec

src/dstack/_internal/server/services/plugins.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from backports.entry_points_selectable import entry_points # backport for Python 3.9
66

77
from dstack._internal.core.errors import ServerClientError
8+
from dstack._internal.utils.common import run_async
89
from dstack._internal.utils.logging import get_logger
910
from dstack.plugins import ApplyPolicy, ApplySpec, Plugin
1011

@@ -91,11 +92,11 @@ def load_plugins(enabled_plugins: list[str]):
9192
logger.warning("Enabled plugins not found: %s", plugins_to_load)
9293

9394

94-
def apply_plugin_policies(user: str, project: str, spec: ApplySpec) -> ApplySpec:
95+
async def apply_plugin_policies(user: str, project: str, spec: ApplySpec) -> ApplySpec:
9596
policies = _get_apply_policies()
9697
for policy in policies:
9798
try:
98-
spec = policy.on_apply(user=user, project=project, spec=spec)
99+
spec = await run_async(policy.on_apply, user=user, project=project, spec=spec)
99100
except ValueError as e:
100101
msg = None
101102
if len(e.args) > 0:

src/dstack/_internal/server/services/runs.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ async def get_plan(
283283
) -> RunPlan:
284284
# Spec must be copied by parsing to calculate merged_profile
285285
effective_run_spec = RunSpec.parse_obj(run_spec.dict())
286-
effective_run_spec = apply_plugin_policies(
286+
effective_run_spec = await apply_plugin_policies(
287287
user=user.name,
288288
project=project.name,
289289
spec=effective_run_spec,
@@ -382,7 +382,7 @@ async def apply_plan(
382382
force: bool,
383383
) -> Run:
384384
run_spec = plan.run_spec
385-
run_spec = apply_plugin_policies(
385+
run_spec = await apply_plugin_policies(
386386
user=user.name,
387387
project=project.name,
388388
spec=run_spec,

src/dstack/_internal/server/services/volumes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ async def create_volume(
205205
user: UserModel,
206206
configuration: VolumeConfiguration,
207207
) -> Volume:
208-
spec = apply_plugin_policies(
208+
spec = await apply_plugin_policies(
209209
user=user.name,
210210
project=project.name,
211211
# Create pseudo spec until the volume API is updated to accept spec

0 commit comments

Comments
 (0)