【问题标题】:Why is Github Actions workflow scheduled with cron not triggering at the right time?为什么 Github Actions 工作流安排的 cron 没有在正确的时间触发?
【发布时间】:2021-03-15 20:34:39
【问题描述】:

我有一个 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 }} 

Github Repo

【问题讨论】:

  • 我现在遇到这个问题,你有没有找到解决方案/解释?
  • @gowerc 这个问题在几天后以某种方式解决了。我猜这个问题出在 Github 上。现在,代码按时运行,每小时运行一次。跑步之间有大约一个小时的间隔。
  • 我也有同样的问题,也在寻找答案
  • 我联系了 gh 支持,他们说他们知道,但他们的公共路线图上没有任何内容
  • 注意:但是,运行计划作业的最短时间已更改为 5 分钟。换句话说,* * * * * 的 cron 作业不会每分钟运行一次,而是 5 分钟。

标签: python time cron github-actions


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    当您使用 计划 设置 GitHub 操作工作流程时,例如每 10 分钟一次,您实际上是在请求 GitHub 为您安排该工作流程。无法保证工作流每 10 分钟运行一次。

    在 GitHub 支持社区 (No assurance on scheduled jobs?) 的一次讨论中,Github 合作伙伴@brightran 多次表示,触发预定工作流时可能会有延迟:

    一般情况下,延迟时间约为 3 到 10 分钟。有时,它可能 更多,甚至几十分钟,或超过一小时。

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

    Source

    【讨论】:

      猜你喜欢
      • 2022-11-02
      • 1970-01-01
      • 2023-01-11
      • 2021-09-15
      • 2021-11-08
      • 2015-08-14
      • 1970-01-01
      • 2022-11-08
      • 1970-01-01
      相关资源
      最近更新 更多