From: Alexander Goussas Date: Fri, 31 Oct 2025 03:03:44 +0000 (-0500) Subject: feat: add compose service to run cronjob that triggers bot X-Git-Url: http://git.frustrated-labs.net/?a=commitdiff_plain;h=a04a707f6253fa8b4ca7111323b85c38dade7a6e;p=squad-rotation-bot.git feat: add compose service to run cronjob that triggers bot --- diff --git a/docker-compose.yaml b/docker-compose.yaml index c97c85e..f2f5502 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -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}" diff --git a/scripts/crontab b/scripts/crontab index 7357771..6f1a9e6 100644 --- a/scripts/crontab +++ b/scripts/crontab @@ -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 index 0000000..fd51597 --- /dev/null +++ b/scripts/crontab.test @@ -0,0 +1,2 @@ +* * * * * echo "hello world" >> /var/log/cron.log +