为什么使用 cron 安排的 Github Actions 工作流没有在正确的时间触发?

Upa*_*Das 10 python cron time github-actions

我有一个每小时触发一次的 Github Actions 工作流。

虽然工作流确实运行,但它不会在计划的时间运行,即它不会在整点运行。有可能超过 30 分钟的延迟。我不知道这是为什么。

它不是工作流本身,因为它会在我在大约 30 秒内手动运行时执行。

有人可以告诉我是什么导致了延迟?

是时区问题吗?即便如此,两次连续的工作流运行之间应该有 1 小时的固定间隔,但事实并非如此。

这是代码。

# This is a basic workflow to help you get started with Actions

name: Email every hour

# Controls when the action will run. 
on:
  # Triggers the workflow on push or pull request events but only for the main branch
  push:
    branches: [ main ]
  pull_request:
    branches: [ main ]
  schedule:
    - cron: "0 */1 * * *"

  # Allows you to run this workflow manually from the Actions tab
  workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
  # This workflow contains a single job called "build"
  build:
    # The type of runner that the job will run on
    runs-on: ubuntu-latest
    strategy:
      matrix:
        python-version: [3.8]

    # Steps represent a sequence of tasks that will be executed as part of the job
    steps:
      # Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
      - uses: actions/checkout@v2

      # Set up Python environment
      - name: Set up Python ${{ matrix.python-version }}
        uses: actions/setup-python@v2
        with:
          python-version: ${{ matrix.python-version }}

      # Install dependencies
      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install -r requirements.txt
          
      # Run script to send email
      - name: Run script
        run: python emailer.py
        env:
          EMAIL_USER: ${{ secrets.EMAIL_USER }}
          EMAIL_PASSWORD: ${{ secrets.EMAIL_PASSWORD }}
          TO_EMAIL: ${{ secrets.TO_EMAIL }} 
Run Code Online (Sandbox Code Playgroud)

Github 仓库

Gui*_*urd 7

当您使用schedule设置 GitHub Actions 工作流程时,比如每 10 分钟一次,您实际上是在请求 GitHub 为您安排该工作流程。不能保证工作流每 10 分钟运行一次。

在 GitHub 支持社区的一次讨论中(对预定的工作没有保证?),Github 合作伙伴@brightran说很多时候,触发预定的工作流时可能会有延迟:

一般延迟时间为3~10分钟左右。有时,可能会更长,甚至几十分钟,或者超过一个小时。

他还表示,如果延迟时间太长,当天可能不会触发预定的工作流。因此,不建议将 GitHub Actions 计划工作流用于需要执行保证的生产任务。

来源

  • 我想知道现在是否有所改变。我可以理解延迟,但事实上它甚至可能无法运行,这似乎完全是疯狂的。他们也可能只是告诉您不要使用它。 (5认同)

小智 -4

github 上的 Cron 作业操作根据 UTC 时间触发。另一方面,延迟可能只是服务器端问题。