Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Github Actions workflow scheduled with cron not triggering at the right time?

I have a Github Actions workflow that is triggered every hour, on the hour.

While the workflow does run, it does not run at the time it is scheduled i.e. it does not run on the hour. There is a delay which may be of more than 30 minutes. I don't know why this is.

It is not the workflow itself because it executes when I manually run it in approximately 30 seconds.

Can someone please tell me what is causing the delay?

Is it a time-zone issue? Even so, there should be a fixed interval of 1 hour between two consecutive workflow runs which is not the case.

This is the code.

# 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

like image 812
Upamanyu Das Avatar asked Dec 03 '20 19:12

Upamanyu Das


People also ask

Do GitHub Actions jobs run sequentially?

A workflow run is made up of one or more jobs , which run in parallel by default. To run jobs sequentially, you can define dependencies on other jobs using the jobs.


1 Answers

When you set up a GitHub Actions workflow with a schedule, say for once every 10 minutes, you're essentially requesting GitHub to schedule that workflow for you. There is no guarantee that the workflow will run every 10 minutes.

In a discussion in the GitHub Support Community (No assurance on scheduled jobs?), Github partner @brightran said that many times, there may be a delay when triggering the scheduled workflow:

Generally, the delay time is about 3 to 10 minutes. Sometimes, it may be more, even dozens of minutes, or more than one hour.

He also said that if the delay time is too long, the scheduled workflow may be not triggered at that day. Therefore, it's not recommended to use GitHub Actions scheduled workflows for production tasks that require execution guarantee.

Source

like image 157
GuiFalourd Avatar answered Oct 07 '22 17:10

GuiFalourd