Skip to content

Commit

Permalink
Merge pull request #151 from Bahmni/BS-204
Browse files Browse the repository at this point in the history
BS-204 | Cron job to Purge Old Jobs (> 48 hours)
  • Loading branch information
vijayanandtwks authored Jul 28, 2023
2 parents 1711d61 + afdc054 commit 6616ce0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
11 changes: 10 additions & 1 deletion package/docker/openmrs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ RUN yum install -y \
mysql-client \
gettext-base \
gettext \
acl
acl \
cronie

# Modify file permissions for document_images directory
RUN setfacl -d -m o::rx -m g::rx /home/bahmni/document_images/
Expand All @@ -98,6 +99,14 @@ RUN chmod +x add_hibernate_properties.sh
RUN ./add_hibernate_properties.sh
RUN rm -rf add_hibernate_properties.sh

# Add cron job to run every 1 hour to purge old exported files
COPY package/resources/purge_files.sh /openmrs/
RUN chmod +x /openmrs/purge_files.sh
RUN echo "0 * * * * /openmrs/purge_files.sh" > /etc/cron.d/purge_files
RUN chmod 0644 /etc/cron.d/purge_files
RUN crontab /etc/cron.d/purge_files
RUN /usr/sbin/crond

RUN rm -rf /tmp/artifacts

CMD ["./bahmni_startup.sh"]
18 changes: 18 additions & 0 deletions package/resources/purge_files.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

dir_path="/openmrs/data/fhirExports"
log_file="/openmrs/data/purge.log"

cutoff_time=$(( 48 * 60 ))

log_message() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$log_file"
echo "$1"
}

if [ ! -d "$dir_path" ]; then
log_message "Error: Directory $dir_path not found."
exit 1
fi

find "$dir_path" -type f -mmin +"$cutoff_time" -delete

0 comments on commit 6616ce0

Please sign in to comment.