{"id":13586886,"url":"https://github.com/rayyansys/swarm-scheduler","last_synced_at":"2025-04-07T18:35:08.965Z","repository":{"id":73895675,"uuid":"109352132","full_name":"rayyansys/swarm-scheduler","owner":"rayyansys","description":"A distributed scheduler for docker swarm mode using Compose and Cron","archived":false,"fork":false,"pushed_at":"2020-04-27T20:42:38.000Z","size":11,"stargazers_count":64,"open_issues_count":1,"forks_count":10,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-03-27T13:18:10.502Z","etag":null,"topics":["cron","cron-service","cron-tasks","cronjob","distributed","docker","scheduler","swarm","swarm-scheduler","swarmmode"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rayyansys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-11-03T04:28:57.000Z","updated_at":"2024-02-28T19:32:10.000Z","dependencies_parsed_at":null,"dependency_job_id":"d0c7b1d4-3782-4d56-a994-d2526886bef3","html_url":"https://github.com/rayyansys/swarm-scheduler","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayyansys%2Fswarm-scheduler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayyansys%2Fswarm-scheduler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayyansys%2Fswarm-scheduler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rayyansys%2Fswarm-scheduler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rayyansys","download_url":"https://codeload.github.com/rayyansys/swarm-scheduler/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247707842,"owners_count":20982859,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cron","cron-service","cron-tasks","cronjob","distributed","docker","scheduler","swarm","swarm-scheduler","swarmmode"],"created_at":"2024-08-01T15:05:52.875Z","updated_at":"2025-04-07T18:35:08.584Z","avatar_url":"https://github.com/rayyansys.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# swarm-scheduler\n\nMany solutions out there explain how to run cron tasks using docker.\nHowever, none of them does that in a distributed manner and make use\nof the swarm mode orchestration.\nWith swarm-scheduler, you can do that with additional benefits.\n\nEach time a task is run, it is scheduled on an arbitrary node.\nMoreover, resource reservations and/or limitations can be applied on tasks\naccording to the needs. Tasks also run inside any container image, let it\nbe ruby, python, php, ...etc or even an application specific image.\nNo new syntax to learn, just use the [docker compose](https://docs.docker.com/compose/compose-file) file syntax.\n\nHere are the steps required to achieve this:\n\n### 1. Deploy the cron stack\n\nFirst thing to do is to write a docker stack yaml file describing\nyour cron tasks as explained in the introduction.\nAn example file is located here with the name `cron-services-example.yml`.\nYou can include any configuration as long as you abide with the following\nrestrictions:\n\n1. Set `command` to run the task command.\n2. `replicas` should be set to 0, otherwise the task will run \nas soon as the service is deployed for the number of times you specified.\n3. Set `restart_policy.condition` to `none`. If you set to `on-failure`,\nthe task will restart automatically on failure. If set to `any` (default),\nit will continuously restart. Both cases are typically not needed in cron tasks.\n\nOnce ready, deploy your cron stack on the swarm cluster:\n\n    docker stack deploy -c cron-stack-example.yml cron\n\n### 2. Deploy the crontab schedule\n\nA standard crontab file is used to schedule the tasks.\nThe only requirement is to set the cron task command to launch the corresponding service.\nFor example if you defined a service called `service1` in the cron stack,\nand you want to run it once every minute, your crontab file should look like:\n\n    * * * * * root run-task cron_service1\n\nOnce ready, deploy your crontab file as a docker config:\n\n    docker config create crontab.v1 crontab-example\n\n### 3. Deploy the scheduler\n\nWith everything in place, it is time to deploy the scheduler itself\nand start the action:\n\n    docker service create --name scheduler_manager \\\n        --mount type=bind,source=/var/run/docker.sock,target=/var/run/docker.sock \\\n        --env DOCKER_URL=unix:///var/run/docker.sock \\\n        --config source=crontab.v1,target=/crontab \\\n        --constraint node.role==manager \\\n        rayyanqcri/swarm-scheduler\n\nAlternatively, clone this repo then deploy the stack `scheduler-service.yml`:\n\n    docker stack deploy -c scheduler-service.yml scheduler\n\n### Watch the service logs\n\nOne of the benefits of running cron tasks as docker services is that\nyou can see the output of the tasks using docker logs. With our\nexample, and the service name is service1:\n\n    docker service logs cron_service1\n\n### Updating the crontab or the cron stack\n\nIf you need to modify your cron tasks defined in the cron stack above,\nuse `docker service update ...` to update the existing cron services and\n`docker service create ...` to add new cron services.\n\nAlternatively, just remove the cron stack and add it again with the modified file:\n\n    docker stack rm cron\n    docker stack deploy -c modified-cron-stack.yml cron\n\nIf what you need is just to change the cron schedule, create a newer version\nfor the docker config.\n\n    docker config create crontab.v2 crontab-example-modified \u0026\u0026 \\\n    docker service update \\\n        --config-add source=crontab.v2,target=crontab \\\n        --config-rm crontab.v1 \\\n        scheduler_manager \u0026\u0026 \\\n    docker config rm crontab.v1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayyansys%2Fswarm-scheduler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frayyansys%2Fswarm-scheduler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frayyansys%2Fswarm-scheduler/lists"}