簡體   English   中英

在 Azure 中運行 Python 腳本

[英]Running Python Scripts in Azure

我有一個帶有 some.py 腳本的 GitHub 存儲庫。 通過 cron 調度程序讓它們在 Azure 中運行的步驟是什么?

我的建議是使用具有時間觸發器綁定Azure Python 函數並從那里調用您的 Python 模塊。

一個簡單的示例項目結構可能如下所示

├── function-app/
│   ├── __init__.py
│   └── function.json
└── shared/
    └── your_module.py

其中__init__.py包含根據 cron 計划執行的 Azure Function 包裝器代碼

from __app__.shared.your_module import your_function

def main(mytimer: func.TimerRequest) -> None:
    utc_timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()

    logging.info('Python timer trigger function ran at %s', utc_timestamp)

    # call your_function() here

function.json包含 cron 計划表達式,在此示例中每 6 小時運行一次。

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 */6 * * *"
    }
  ]
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM