forked from microsoft/fabric-cicd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_environment.py
53 lines (40 loc) · 1.77 KB
/
_environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""Functions to process and deploy Environment item."""
import logging
from fabric_cicd import FabricWorkspace
logger = logging.getLogger(__name__)
def publish_environments(fabric_workspace_obj: FabricWorkspace) -> None:
"""
Publishes all environment items from the repository.
Environments can only deploy the shell; compute and spark configurations are published separately.
Args:
fabric_workspace_obj: The FabricWorkspace object containing the items to be published.
"""
item_type = "Environment"
for item_name in fabric_workspace_obj.repository_items.get(item_type, {}):
fabric_workspace_obj._publish_item(
item_name=item_name,
item_type=item_type,
skip_publish_logging=True,
)
item_guid = fabric_workspace_obj.repository_items[item_type][item_name].guid
_publish_environment(fabric_workspace_obj, item_guid=item_guid)
def _publish_environment(fabric_workspace_obj: FabricWorkspace, item_guid: str) -> None:
"""
Publishes compute settings and libraries for a given environment item.
Args:
fabric_workspace_obj: The FabricWorkspace object.
item_guid: Guid of the environment item whose compute settings are to be published.
"""
logger.info("Publishing Libraries & Spark Settings")
# Publish updated settings
# https://learn.microsoft.com/en-us/rest/api/fabric/environment/spark-libraries/publish-environment
fabric_workspace_obj.endpoint.invoke(
method="POST",
url=f"{fabric_workspace_obj.base_api_url}/environments/{item_guid}/staging/publish",
base_delay=5,
retry_after=120,
max_retries=20,
)
logger.info("Published")