Welcome to the Programming Cafe!

Plan for today

Work on your own project 45 min
Scheduling Scripts 45 min
Wrap-up 10 min
Drinks!

Programming Cafe

  • R-Cafe
  • Presentation, demo, exercise
  • Community event
  • Open to UU, HU, UMCU
  • Researchers, students, support staff
  • It is OK to work on your own code

Programming Cafe

  • Ideas for topics? Let us know!
  • Wanted: Core team members
  • Feedback welcome!

Use the link below or talk to us

tinyurl.com/uucafe

Scheduling Scripts

What Is Job Scheduling?

In programming, job scheduling involves automating the execution of scripts or programs at specified times or intervals.

Why Would We Want To Schedule Jobs?

  • Automation
  • Efficiency
  • Consistency
  • Updating Things
  • Integration
  • Scalability

How Can We Schedule Jobs?

Using a job scheduler! These are applications already available on your computer. You use them for controlling unattended background program execution of jobs.

They differ per operating system:

  • Windows: Windows Task Scheduler

  • MacOS & Linux: cron

Windows Task Scheduler

Windows Task Scheduler is a job scheduler in Microsoft Windows that launches computer programs or scripts at pre-defined times or after specified time intervals.

Here is a written tutorial: https://www.tomsguide.com/how-to/how-to-use-task-scheduler-on-windows

cron

The cron command-line utility is a job scheduler on Unix-like operating systems. Users who set up and maintain software environments use cron to schedule jobs (commands or shell scripts), also known as cron jobs, to run periodically at fixed times, dates, or intervals.

The actions of cron are driven by a crontab (cron table) file, a configuration file that specifies shell commands to run periodically on a given schedule. The syntax of each line within a crontab file expects a cron expression made of five fields which represent the time to execute the command, followed by a shell command to execute.

# ┌───────────── minute (0–59)
# │ ┌───────────── hour (0–23)
# │ │ ┌───────────── day of the month (1–31)
# │ │ │ ┌───────────── month (1–12)
# │ │ │ │ ┌───────────── day of the week (0–6) (Sunday to Saturday;
# │ │ │ │ │                                   7 is also Sunday on some systems)
# │ │ │ │ │
# │ │ │ │ │
# * * * * * <command to execute>

Here is a written tutorial: https://itsfoss.com/cron-job/

Some Considerations When Scheduling Jobs

  • In Windows Task Scheduler, double-check the Conditions.

  • With cron, you have to pay attention to the syntax

  • You might need Administrator Privileges to run jobs.

  • Remember to specify working directories.

The Big Picture…

  • Great test for automation/reproducibility, since you might want the scripts to run in the background without any user interaction.

  • If you can schedule one script, you can schedule multiple! If you can schedule multiple scripts, you may as well start looking into workflow orchestration using shell scripts, batch files, MAKE, Apache Airflow…

  • At this point, we are getting into background processes running on your computer. You can create multiple background processes that are running in parallel from the command line, or from a Python/R script. This is where parallelization and potentially, when you have many parallel tasks, High Performance Computing starts.

Bonus

GitHub Actions

R Packages