Kaynağa Gözat

fix cronjob

Nikos Atlas 9 ay önce
ebeveyn
işleme
eb49e76994

+ 7 - 4
deploy/Dockerfile

@@ -5,8 +5,8 @@ ENV PYTHONDONTWRITEBYTECODE 1
 ENV PYTHONUNBUFFERED 1
 ENV PYTHONPATH "src"
 
-RUN apt-get update && apt-get install -y cron
-
+RUN apt-get update && apt-get install -y cron && touch /var/log/cron.log
+RUN service cron start
 # Set the working directory in the container
 WORKDIR /app
 COPY requirements.txt /app
@@ -15,15 +15,18 @@ RUN pip install --no-cache-dir -r requirements.txt
 
 # Copy the current directory contents into the container at /app
 COPY . /app
-WORKDIR /app/src
+WORKDIR /app
 # Collect static files
 RUN python manage.py migrate
 RUN python manage.py collectstatic --noinput
 RUN python manage.py crontab add
 RUN python manage.py crontab show
+RUN mkdir src/artifacts
 
 WORKDIR /app
 # Make port 8000 available to the world outside this container
 EXPOSE 8000
+COPY start.sh /app
+RUN chmod +x /app/start.sh
 # Run app.py when the container launches
-CMD ["gunicorn", "--bind", "0.0.0.0:8000", "src.wsgi:application"]
+CMD ["./start.sh"]

+ 0 - 0
src/manage.py → manage.py


+ 1 - 1
src/telecaster/Clients/CosmohomeClient.py

@@ -270,5 +270,5 @@ def generate_xml():
 
 def generate_xml_task():
     xml = generate_xml()
-    with open('cosmohome_products.xml', 'w') as file:
+    with open('artifacts/cosmohome_products.xml', 'w') as file:
         file.write(xml)

+ 2 - 2
src/telecaster/settings.py

@@ -125,7 +125,7 @@ STATIC_URL = 'static/'
 
 DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
 
-
+CRONTAB_COMMAND_PREFIX = 'PYTHONPATH=/app/src'  # Required for crontabs inside docker.
 CRONJOBS = [
-    ('*/23 * * * *', 'src.telecaster.Clients.CosmohomeClient.generate_xml_task'),
+    ('*/5 * * * *', 'src.telecaster.Clients.CosmohomeClient.generate_xml_task'),
 ]

+ 1 - 1
src/telecaster/views/CosmohomeView.py

@@ -16,7 +16,7 @@ class CosmohomeView(viewsets.ViewSet):
     @classmethod
     @action(methods=['get'], detail=False, url_path='xml')
     def xml(cls, request: Request, *args, **kwargs) -> HttpResponse:
-        file = "cosmohome_products.xml"
+        file = "artifacts/cosmohome_products.xml"
         try:
             with open(file, 'rb') as f:
                 return HttpResponse(f.read(), content_type='text/xml')

+ 7 - 0
start.sh

@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -ex
+
+service cron start
+
+gunicorn --bind 0.0.0.0:8000 src.wsgi:application