]> git.frustrated-labs.net Git - squad-rotation-bot.git/commitdiff
feat: add compose service to run cronjob that triggers bot
authorAlexander Goussas <[email protected]>
Fri, 31 Oct 2025 03:03:44 +0000 (22:03 -0500)
committerAlexander Goussas <[email protected]>
Fri, 31 Oct 2025 03:04:39 +0000 (22:04 -0500)
docker-compose.yaml
scripts/crontab
scripts/crontab.test [new file with mode: 0644]

index c97c85ed5db33063396f5c1c6b35fb28be993019..f2f5502af46b8da99332e3aebb9af62442c13db4 100644 (file)
@@ -1,18 +1,40 @@
 services:
   bot:
     image: "aloussase69/squad-rotation-bot"
+    container_name: squad-rotation-bot
     build:
       context: .
     environment:
       WEB_HOOK_URL: "${WEB_HOOK_URL:-https://example.com}"
       DATABASE_URL: "${DB_URL:-postgresql://postgres:postgres@db:5432/postgres?application_name=squad_rotation_bot}"
     ports:
-      - "8080:8080"
+      - "3000:8080"
     depends_on:
       - db
 
+  cron:
+    image: "ubuntu:22.04"
+    container_name: cronjob
+    restart: unless-stopped
+    command: >
+      bash -c "
+        apt-get update && apt-get install -y cron curl
+        crontab /apps/crontab
+        crontab -l
+        touch /var/log/cron.log
+        cron
+        echo \"Date inside cron container is: $(date)\"
+        tail /var/log/cron.log -f
+      "
+    volumes:
+      - "./scripts/crontab:/apps/crontab"
+    depends_on:
+      - bot
+      - db
+
   db:
     image: "postgres:17"
+    container_name: postgres_db
     restart: unless-stopped
     environment:
       POSTGRES_USER: "${DB_USER:-postgres}"
index 7357771d05f7e318bcf81f067fdab7e5efa7c8a7..6f1a9e6d0ef36d3bdab365c2e4cdcd198c560179 100644 (file)
@@ -1 +1,4 @@
-0 7 * * 1-5
+# The second field is the hour. It's in UTC, so make sure to use the correct
+# value for your TZ. For example, I am in Ecuador, which is UTC-5, so if I want
+# the bot to run at 7AM, I need to set the hour to 2AM (e.g. 2).
+0 2 * * 1-5 curl "http://bot:8080/api/v1/rotation/trigger" >> /var/log/cron.log 2>&1
diff --git a/scripts/crontab.test b/scripts/crontab.test
new file mode 100644 (file)
index 0000000..fd51597
--- /dev/null
@@ -0,0 +1,2 @@
+* * * * * echo "hello world" >> /var/log/cron.log
+