Skip to content

Commit

Permalink
Implement cron as separate container #1
Browse files Browse the repository at this point in the history
  • Loading branch information
kcloud committed Jan 28, 2023
1 parent da759ec commit 52dd4b7
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Dockerfile.cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM python:3.10

ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y cron && which cron && rm -rf /etc/cron.*/*
RUN apt-get -y install python3-pip
RUN pip install --upgrade pip

RUN mkdir /code
WORKDIR /code
ADD requirements.txt /code/
RUN pip install --upgrade pip && pip install -r requirements.txt
ADD . /code/
RUN chmod +x /code

RUN ln -s /usr/local/bin/python3 /code/scorpio/python
ADD ./cron/scorpio_cron /etc/cron.d/scorpio_cron
RUN chmod 644 /etc/cron.d/scorpio_cron
RUN crontab /etc/cron.d/scorpio_cron
RUN mkdir -p /var/log/scorpio-cron
ENTRYPOINT ["/code/cron/entrypoint.sh"]
CMD ["cron","-f","-l","2"]
7 changes: 7 additions & 0 deletions cron/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/sh

env >> environment

# execute CMD
echo "$@"
exec "$@"
7 changes: 7 additions & 0 deletions cron/scorpio_cron
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Don't remove empty line at end of file. It is required for cron to run.
SCORPIO_ROOT=/code/scorpio
00,30 * * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.IndexAgents" >> /var/log/scorpio-cron/scorpio-agents.txt 2>&1
10,40 * * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.IndexCollections" >> /var/log/scorpio-cron/scorpio-collections.txt 2>&1
20,50 * * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.IndexObjects" >> /var/log/scorpio-cron/scorpio-objects.txt 2>&1
5 0,12 * * * $SCORPIO_ROOT/python -u /code/manage.py runcrons "indexer.cron.CleanUpCompleted" >> /var/log/scorpio-cron/scorpio-cleanupcompleted.txt 2>&1

0 comments on commit 52dd4b7

Please sign in to comment.