0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

[Azure][CronJob][ScheduledJob] Azure環境におけるCronJob (定期実行ジョブ)

Last updated at Posted at 2025-06-01

CronJob(定期実行ジョブ)とは

  • 時間ベースで自動的に処理を実行する仕組み
  • Scheduled JobTime-triggered JobTimer-based Workflowと呼ばれることもある

Azure環境における選択肢

サービス名 種別 マネージド性 主な用途・特徴
Azure Functions Timer Trigger サーバーレス 軽量コードの定期実行、簡易スケジューラ
Logic Apps Recurrence ノーコードワークフロー GUIで定期処理+SaaS連携
AKS CronJob(Kubernetes CronJob) Kubernetesネイティブ ❌(AKSのみ) コンテナの定期実行、柔軟だが運用コストあり
Azure Data Factory (Trigger) データパイプライン ETL処理、データ転送・集計の定期実行

実装方法

サービス名 スタイル 実装方法(手順の概要)
Azure Functions (Timer Trigger) コード 1. Azure Functions プロジェクト作成
2. TimerTrigger 属性で関数作成(cron式指定)
3. デプロイ
Logic Apps (Recurrence) GUI 1. AzureポータルでLogic App作成
2. トリガー(Recurrence)を選択
3. 後続アクションをGUIで構成
AKS CronJob(Kubernetes CronJob) YAML(コード) 1. CronJob用の cronjob.yaml を作成(cron式、Pod定義)
2. kubectl applyでデプロイ
Azure Data Factory (Trigger) GUI 1. ADFポータルでパイプライン作成
2. トリガー(Schedule)を追加
3. 時刻や繰り返し間隔をGUIで設定

ユースケース

ユースケース 選択肢
軽量な定期処理(ログ清掃、APIコールなど) Azure Functions Timer Trigger
GUIでSaaSとつないで簡単に自動化したい Logic Apps Recurrence
コンテナで処理内容を細かく制御したい AKS CronJob
データ移動や集計、ETL処理を定期実行したい Azure Data Factory

以下に、「呼び出す側」「呼び出される側」の関係を、毎朝6時にファイルをインポートするケースにおいて、各サービスごとに明確に整理しました。


Azure Functions (Timer Trigger)

種別 内容
呼び出す側 Azure FunctionsのTimer Trigger
function.jsonでCronスケジュールを設定
呼び出される側 Python/C#/JavaScriptなどで書かれた main() 関数(ファイルインポート処理)

呼び出す側(function.json)

{
  "bindings": [
    {
      "name": "mytimer",
      "type": "timerTrigger",
      "direction": "in",
      "schedule": "0 0 6 * * *"
    }
  ]
}

呼び出される側(Python)

def main(mytimer: func.TimerRequest) -> None:
    # ファイルインポート処理

Logic Apps (Recurrence + HTTPアクション)

種別 内容
呼び出す側 Logic Apps の Recurrenceトリガー → HTTP アクションで API を呼び出す
呼び出される側 外部のHTTP API(例:Azure FunctionやExpressなどのエンドポイント)

呼び出す側(Logic Apps の構成 GUI 例)

[Recurrence @ 6:00] → [HTTP POST to https://myapi.com/import]

呼び出される側(例:Node.js)

app.post('/import', (req, res) => {
  // ファイルインポート処理
  res.send('done');
});

AKS CronJob(Kubernetes CronJob)

種別 内容
呼び出す側 Kubernetes の CronJob マニフェスト(YAMLで定義されたスケジューラ)
呼び出される側 コンテナ内のコード(app.pymain()など)

呼び出す側(cronjob.yaml)

apiVersion: batch/v1
kind: CronJob
metadata:
  name: file-import-job
spec:
  schedule: "0 6 * * *"
  jobTemplate:
    spec:
      template:
        spec:
          containers:
          - name: file-import
            image: myregistry.azurecr.io/import-image:latest
            command: ["python", "app.py"]
          restartPolicy: OnFailure

呼び出される側(app.py)

def main():
    print("Importing files...")
    # ファイルのダウンロード・処理
    print("Done.")

if __name__ == "__main__":
    main()

Azure Data Factory (Trigger + Webアクティビティ)

種別 内容
呼び出す側 ADF の スケジュールトリガー + Webアクティビティ
呼び出される側 HTTPエンドポイント(例:Azure FunctionsやREST API)

呼び出す側(ADF パイプライン GUI)

  • トリガー:毎朝6時
  • アクティビティ:「Webアクティビティ」→ POST https://my-function.azurewebsites.net/api/import

呼び出される側(Azure Functions)

def main(req: func.HttpRequest) -> func.HttpResponse:
    # ファイルインポート処理
    return func.HttpResponse("OK")

参考リンク

Azure Functions (Timer Trigger)

Azure Logic Apps (Recurrence Trigger)

AKS CronJob(Kubernetes CronJob)

Azure Data Factory (Schedule Trigger)

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?