当我通过 SDK 创建我的工作区包时,如何使它的配置状态为 "Succeeded" 而不是 "Incomplete"?

How can I get the provisioning state of my Workspace Package to be "Succeeded" and not "Incomplete" when I create it through the SDK?

我正在使用 azure-synapse-artifacts 库中的 ArtifactsClient 并尝试上传新的工作区包。当通过 UI 手动执行此操作时,它起作用并且我的供应状态设置为“成功”。当我尝试通过 SDK 执行相同操作时,我不会获得“成功”,因此无法在我的 Spark Pool 中使用该库。

这是我使用的代码:

from time import sleep

from azure.identity import DefaultAzureCredential
from azure.synapse.artifacts import ArtifactsClient


client = ArtifactsClient(credential=DefaultAzureCredential(), endpoint="https://mysynapseworkspace.dev.azuresynapse.net")

ws = client.workspace.get()

library_client = client.library
wheel_name = 'dalib.whl'

poller = library_client.begin_create(wheel_name)
while not poller.done():
    print(poller.status())
    sleep(1)

whl = open('C:\path\to\wheelfile\wheel_tester-0.0.1-py3-none-any.whl', 'rb')
library_client.append(library_name=wheel_name, content=whl)
whl.close()

好的,我解决了这个问题。

似乎在您创建了库并调用了 append() 方法之后,您还必须使用 begin_flush() 才能将配置状态设置为“成功”。但是,我发现的任何文档中都没有提到这一点。如果有人遇到与我相同的问题,我 post 下面的工作代码:

from time import sleep

from azure.core.exceptions import ResourceExistsError
from azure.identity import DefaultAzureCredential
from azure.synapse.artifacts import ArtifactsClient

credential = DefaultAzureCredential()

client = ArtifactsClient(credential=credential, endpoint="https://synws.dev.azuresynapse.net")

ws = client.workspace.get()


library_client = client.library
wheel_name = 'wheel_tester-0.0.1-py3-none-any.whl'
whl = open(f'C:\path\to\wheelfile\{wheel_name}', 'rb')

try:
    print('creating library')
    poller = library_client.begin_create(wheel_name)
    while not poller.done():
        print(poller.status())
        sleep(1)
    print(poller.status())
    print(poller.result())
except ResourceExistsError as ree:
    print('resource already exists.')

print('appending content')
library_client.append(library_name=wheel_name, content=whl)

print('flushing library')
lro_poller = library_client.begin_flush(library_name=wheel_name)
while not lro_poller.done():
    print(lro_poller.status())
    sleep(1)

print(lro_poller.status())
print(lro_poller.result())

whl.close()