Skip to content

Commit

Permalink
feat: add scheduled cron tasks for repeated actions
Browse files Browse the repository at this point in the history
- Generates PDFs every few minutes
- Checks plagiarism every week
- Sends weekly emails
- Synchronises enrolments every day
  • Loading branch information
macite committed Dec 3, 2021
1 parent 4661cd7 commit 2f9ca9c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
12 changes: 8 additions & 4 deletions pdfGen/crontab
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
10,15,20,25,30,35,40,45,50,55 * * * * /doubtfire/lib/shell/generate_pdfs.sh
0 5 * * 1,3,5 /doubtfire/lib/shell/check_plagiarism.sh
0 7 * * 1 /doubtfire/lib/shell/send_weekly_emails.sh
0 1 * * * /doubtfire/lib/shell/sync_enrolments.sh
SHELL=/bin/bash
BASH_ENV=/container.env
PATH=/tmp/texlive/bin/x86_64-linux:/usr/local/bundle/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bundle/bin

10,15,20,25,30,35,40,45,50,55 * * * * /doubtfire/lib/shell/generate_pdfs.sh > /proc/1/fd/1 2>/proc/1/fd/2
0 5 * * 1,3,5 /doubtfire/lib/shell/check_plagiarism.sh > /proc/1/fd/1 2>/proc/1/fd/2
0 7 * * 1 /doubtfire/lib/shell/send_weekly_emails.sh > /proc/1/fd/1 2>/proc/1/fd/2
0 1 * * * /doubtfire/lib/shell/sync_enrolments.sh > /proc/1/fd/1 2>/proc/1/fd/2
23 changes: 23 additions & 0 deletions pdfGen/entry_point.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

# Start the run once job.
echo "Docker container has been started"

# Save the docker user environment
declare -p | grep -Ev 'BASHOPTS|BASH_VERSINFO|EUID|PPID|SHELLOPTS|UID' > /container.env
cat /container.env

# Ensure log is present
touch /var/log/cron.log

sleep 1

# Setup crontab - clear then load with file
crontab -r
crontab /etc/cron.d/container_cronjob

echo "RESET CRONTAB" >> /var/log/cron.log


# Run cron and follow log
chmod 644 /etc/cron.d/container_cronjob && cron -f && tail -f /var/log/cron.log > /proc/1/fd/1 2>/proc/1/fd/2
8 changes: 0 additions & 8 deletions pdfGen/script.sh

This file was deleted.

12 changes: 7 additions & 5 deletions pdfgen.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ RUN apt-get update && apt-get install -y \
# Setup the folder where we will deploy the code
WORKDIR /doubtfire

# Crontab file copied to cron.d directory.
COPY "$PDFGEN_HOME"/cronjob /etc/cron.d/container_cronjob

# Install LaTex
COPY "$API_HOME"/.ci-setup /doubtfire/.ci-setup
RUN /doubtfire/.ci-setup/texlive-install.sh
Expand All @@ -39,6 +36,11 @@ ENV PATH /tmp/texlive/bin/x86_64-linux:$PATH

# Copy doubtfire-api source
COPY "$API_HOME" /doubtfire/
COPY "$PDFGEN_HOME"/script.sh /doubtfire/

CMD script.sh
# Crontab file copied to cron.d directory.
COPY "$PDFGEN_HOME"/entry_point.sh /doubtfire/
COPY "$PDFGEN_HOME"/crontab /etc/cron.d/container_cronjob

RUN touch /var/log/cron.log

CMD /doubtfire/entry_point.sh

0 comments on commit 2f9ca9c

Please sign in to comment.