Hion Coding - Blogs share everything
  • HOME
  • ABOUT
  • POSTS
  • CONTACT
  • TOOLS
    CÂU HỎI VÕ ĐÀI TỐI THƯỢNG CONVERT IMAGE TO WEBP
Scheduling your GitHub Actions cron-style

Scheduling your GitHub Actions cron-style

Hion Coding - Blogs share everything
Admin Hion Coding Blogs vochilong.work@gmail.com
9th April 2024

Git/Github

Scheduling your GitHub Actions cron-style

 

Scheduling tasks can be a handy way to automate work, and Cron Jobs is the way to do it. We all have that one recurring task we wish could be done automatically without manual intervention. Not to forget, "That is also for FREE".

Cron jobs are meant for performing regularly scheduled actions such as backups, report generation, and so on. Each of those tasks should be configured to recur indefinitely (for example: once a day/week/month); you can define the point in time within that interval when the job should start.

How to set up a Cron job?

There are a lot of ways to set up Cron Jobs

At the OS level
  1. You can use the inbuilt Windows scheduler
  2. If you are on Ubuntu, you can use the Cron Utility

But most of the time, you would want to keep it away from OS, and closer to your application for that, we can use

At the Application level
  1. use packages like Cron to create a cron job in your NodeJS application, but this cannot run on a serverless stack
  2. use a serverless solution like AWS Lambda, but it requires a lot of setup and credit card
  3. use Firebase cloud functions with scheduling, it is a lot simpler than AWS but requires a credit card.
  4. use a SAAS tool like EasyCron
Our Winner (GitHub actions)

While all of the above are good solutions, the simplest way to do this for hobby projects would be to use GitHub actions because it

  1. is easy to set up through code and coupled with the application code itself
  2. is free for public repos
  3. provides up to 4000 minutes/month for private repos (extremely hard to consume)
  4. allows us to create unlimited jobs and schedules

How do GitHub Actions help?

GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want. You can read more about them here.

Now to set up your own Cron job using GitHub actions,

  1. Go to your GitHub repository (create one if required).

  2. Create file yml: .github/workflows/cron_job.yml

  3. Add your Cron schedule and task to it. Commit the change.
     

    name: Cron Job
    
    on:
      # Triggers the workflow every 5 minutes
      schedule:
        - cron: "*/5 * * * *"
    
    jobs:
      # This workflow contains a single job called "cron"
      cron:
        runs-on: ubuntu-latest
     
        # Steps represent a sequence of tasks that will be executed as part of the job
        steps:
          - name: Run a one-line script
            run: echo "Hello, world!"

    This will run a job to echo "Hello, world!" every 5 minutes.

    Go to the Actions tab and wait for the log to show up. When you click on any execution you'll see details like this

That is how you can schedule a Cron job using GitHub actions.

Note: The scheduled event can be delayed during periods of high loads of GitHub Actions workflow runs. High load times include the start of every hour. To decrease the chance of delay, schedule your workflow to run at a different time of the hour.

See how the job scheduled to run every 5 minutes was delayed a couple of times. Please be mindful of how you use the free resources.
The last and most important thing is that you need to wait patiently. Because GitHub action only allows schedule to run at least once every 5 minutes

Thanks !!! Good luck !!! Hion Coding


Create Release in Github action - How to do it?

26th April 2024

Create Release in Github action - How to do it?

Git/Github

Tạo Release trong Github action - How to do it?

26th April 2024

Tạo Release trong Github action - How to do it?

Git/Github

Auto deployment với GitHub Actions cho cPanel hoặc VPS 🚀

31st March 2024

Auto deployment với GitHub Actions cho cPanel hoặc VPS 🚀

Git/Github

Auto deployment with GitHub Actions for cPanel or VPS 🚀

31st March 2024

Auto deployment with GitHub Actions for cPanel or VPS 🚀

Git/Github

Hion Coding - Blogs share everything


© 2025 Hion Coding DMCA.com Protection Status