安排筆記本執行作業
本頁面說明如何使用 Vertex AI Workbench 執行器,依每小時的時間表執行 Python 筆記本檔案。
事前準備
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Notebooks and Vertex AI APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Notebooks and Vertex AI APIs.
-
如何列出執行作業:
notebooks.executions.list
必要的角色
為確保您的執行個體服務帳戶具備與 Vertex AI Workbench 執行工具互動的必要權限,請要求管理員授予執行個體服務帳戶專案的「Notebooks Viewer」(roles/notebooks.viewer
) IAM 角色。
這個預先定義的角色包含與 Vertex AI Workbench 執行工具互動所需的權限。如要查看確切的必要權限,請展開「必要權限」部分:
所需權限
如要與 Vertex AI Workbench 執行器互動,您必須具備下列權限:
建立執行個體和範例筆記本檔案
在筆記本檔案的第一個儲存格中輸入以下內容:
# Import datetime import datetime # Get the time and print it datetime.datetime.now() print(datetime.datetime.now())
如要確保筆記本檔案已儲存,請依序選取「File」>「Save Notebook」。
排定執行時間
前往 Google Cloud 控制台的「Instances」(執行個體) 頁面。
按一下執行個體名稱旁的「Open JupyterLab」。
Vertex AI Workbench 執行個體會開啟 JupyterLab。
在
File Browser 中,按兩下範例筆記本檔案即可開啟。按一下
「Execute」 按鈕。在「Submit notebooks to Executor」對話方塊的「Type」欄位中,選取「Schedule-based recurring executions」。
根據預設,執行程式會在每小時的
00
分執行筆記本檔案。在「進階選項」中,在「Cloud Storage bucket」欄位中輸入值區名稱,然後按一下「Create and select」。執行程式會將筆記本輸出內容儲存在 Cloud Storage 值區中。
按一下「提交」。
筆記本檔案會依照您設定的時間表自動執行。
完成本文件所述工作後,您可以刪除已建立的資源,避免繼續計費。詳情請參閱「清除所用資源」。
查看、分享及匯入已執行的筆記本檔案
您可以使用執行個體的 JupyterLab 介面,查看筆記本輸出內容、與他人分享結果,以及將已執行的筆記本檔案匯入 JupyterLab。
查看執行結果
在 JupyterLab 的導覽選單中,按一下
「Notebook Executor」按鈕。按一下「執行」分頁標籤。
在要查看的執行作業下方,按一下「查看結果」。
執行程式會在新瀏覽器分頁中開啟結果。
分享執行結果
在執行個體的 JupyterLab 使用者介面中,按一下導覽選單中的
「Notebook Executor」按鈕。按一下「執行」分頁標籤。
在要分享的執行作業旁邊,按一下
選項選單,然後選取「分享執行結果」。按照對話方塊中的指示,將執行結果的存取權授予使用者。
將已執行的筆記本匯入 JupyterLab
在執行個體的 JupyterLab 使用者介面中,按一下導覽選單中的
「Notebook Executor」按鈕。按一下「執行」分頁標籤。
在要匯入的執行作業旁,按一下
選項選單,然後選取「匯入已執行的筆記本」。如果出現「Select Kernel」對話方塊,請選取要用來開啟筆記本的核心。
執行程式會在 JupyterLab 中開啟已執行的筆記本檔案,並將此筆記本檔案儲存在 JupyterLab 檔案瀏覽器中,位於名為 imported_notebook_jobs 的資料夾中。
查看或刪除時間表
您可以使用 Google Cloud 控制台或執行個體的 JupyterLab 使用者介面,查看及刪除排程。
查看時間表
查看排程,瞭解排程的頻率設定,或查看筆記本檔案執行的五個最新結果。
控制台
在 Google Cloud 控制台中,前往「排程」頁面。
針對要查看的時間表,按一下其時間表名稱。
您可以在「排程詳細資料」頁面中查看排程的最近五次執行作業。
按一下執行名稱旁的「查看結果」,即可開啟已執行的筆記本檔案。
執行程式會在新瀏覽器分頁中開啟結果。
JupyterLab
在執行個體的 JupyterLab 使用者介面中,按一下導覽選單中的
「Notebook Executor」按鈕。按一下「時程」分頁標籤。
在要查看的執行作業下方,按一下「查看最新執行結果」。
執行程式會在新瀏覽器分頁中開啟結果。
刪除時間表
刪除排程不會刪除該排程產生的執行作業。
控制台
在 Google Cloud 控制台中,前往「排程」頁面。
選取要刪除的時間表。
按一下「Delete」(刪除) 圖示
。
JupyterLab
在執行個體的 JupyterLab 使用者介面中,按一下導覽選單中的
「Notebook Executor」按鈕。按一下「時程」分頁標籤。
按一下時間表名稱。系統會在 Google Cloud 控制台中開啟該排程的「排程詳細資料」頁面。
按一下「Delete」(刪除) 圖示
。
清除所用資源
如要避免系統向您的 Google Cloud 帳戶收取您在本頁所用資源的費用,請按照下列步驟操作。
刪除執行個體
前往 Google Cloud 控制台的「Instances」(執行個體) 頁面。
選取要刪除的執行個體。
按一下「Delete」(刪除) 圖示
。
刪除專案
如果您使用的是 Vertex AI Workbench 執行個體以外的資源,例如建立排程所需的 Cloud Storage bucket,建議您刪除專案,以免產生額外費用。
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.