Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cron): Run harvester cron job in background (run and clean up log… #71

Merged
merged 4 commits into from
Jun 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions ckan/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@ RUN mkdir -p /var/log/ckan/std && chown -R ckan:ckan /var/log/ckan
COPY docker-entrypoint.d/* /docker-entrypoint.d/
COPY config/ckan_harvesting.conf /etc/supervisord.d/ckan_harvesting.conf

# Copy crontab file to the cron.d directory
ADD config/crontab-harvester /etc/cron.d/crontab-harvester

# Give execution rights on the cron job
RUN chmod 644 /etc/cron.d/crontab-harvester

# Apply cron job
RUN crontab -u ckan /etc/cron.d/crontab-harvester

# Create log file for cron
RUN touch /var/log/cron.log && chown ckan:ckan /var/log/cron.log

# Apply any patches needed to CKAN core or any of the built extensions (not the
# runtime mounted ones)
COPY patches ${APP_DIR}/patches
Expand Down
12 changes: 12 additions & 0 deletions ckan/Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ RUN mkdir -p /var/log/ckan/std && chown -R ckan:ckan /var/log/ckan
COPY docker-entrypoint.d/* /docker-entrypoint.d/
COPY config/ckan_harvesting.conf /etc/supervisord.d/ckan_harvesting.conf

# Copy crontab file to the cron.d directory
ADD config/crontab-harvester /etc/cron.d/crontab-harvester

# Give execution rights on the cron job
RUN chmod 644 /etc/cron.d/crontab-harvester

# Apply cron job
RUN crontab -u ckan /etc/cron.d/crontab-harvester

# Create log file for cron
RUN touch /var/log/cron.log && chown ckan:ckan /var/log/cron.log

# Apply any patches needed to CKAN core or any of the built extensions (not the
# runtime mounted ones)
COPY patches ${APP_DIR}/patches
Expand Down
15 changes: 15 additions & 0 deletions ckan/config/ckan_harvesting.conf
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,18 @@ stderr_logfile=/var/log/ckan/std/fetch_consumer.log
autostart=true
autorestart=true
startsecs=10


[program:crond]

; Full Path to executable, should be path to virtual environment,
; Full path to config file too.

command=/usr/sbin/crond -n

numprocs=1
stdout_logfile=/var/log/cron.log
stderr_logfile=/var/log/cron.log
autostart=true
autorestart=true
startsecs=10
13 changes: 13 additions & 0 deletions ckan/config/crontab-harvester
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# SPDX-FileCopyrightText: Stichting Health-RI
#
# SPDX-License-Identifier: AGPL-3.0-only

# Set the shell to bash
SHELL=/bin/bash

# Source the environment variables
BASH_ENV=/etc/profile.d/custom_env.sh

# Every 15 minutes, run the harvester and clean the harvest log every day at 5am
*/15 * * * * /usr/bin/ckan -c /srv/app/ckan.ini harvester run
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do/can this be configurable through an environment flag?

0 5 * * * /usr/bin/ckan -c /srv/app/ckan.ini harvester clean-harvest-log
8 changes: 8 additions & 0 deletions ckan/docker-entrypoint.d/cp_env_to_cron_env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# SPDX-FileCopyrightText: Stichting Health-RI
#
# SPDX-License-Identifier: AGPL-3.0-only

#!/bin/sh

# Dump environment variables to a file that will be sourced by cron
printenv | sed 's/^\(.*\)$/export \1/g' > /etc/profile.d/custom_env.sh