https://github.com/reddec/compose-scheduler
Simple and lightweight service which can execute services from the same file based on cron expression.
https://github.com/reddec/compose-scheduler
Last synced: about 1 year ago
JSON representation
Simple and lightweight service which can execute services from the same file based on cron expression.
- Host: GitHub
- URL: https://github.com/reddec/compose-scheduler
- Owner: reddec
- License: mit
- Created: 2023-01-23T10:42:51.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2024-06-22T07:59:18.000Z (about 2 years ago)
- Last Synced: 2025-05-03T04:37:55.862Z (about 1 year ago)
- Language: Go
- Homepage: https://reddec.net/articles/portable-stack/
- Size: 21.5 KB
- Stars: 64
- Watchers: 3
- Forks: 5
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Docker-Compose scheduler
Simple and lightweight service which can execute `docker compose run ...` services from the same file based on cron
expression.
Features:
- Zero-configuration by-default
- Designed for docker compose (auto-detect, respects namespace)
- HTTP notifications with retries
Inspired by [ofelia](https://github.com/mcuadros/ofelia).
```yaml
services:
web:
image: "nginx"
labels:
- "net.reddec.scheduler.cron=@daily"
- "net.reddec.scheduler.exec=nginx -s reload"
date:
image: busybox
restart: "no"
labels:
- "net.reddec.scheduler.cron=* * * * *"
scheduler:
image: ghcr.io/reddec/compose-scheduler:1.0.0
restart: unless-stopped
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
```
Supports two modes:
- plain `docker compose run`
- exec command inside service (extra label `net.reddec.scheduler.exec`)
## Usage
```
Application Options:
--project= Docker compose project, will be automatically detected if not set [$PROJECT]
HTTP notification:
--notify.url= URL to invoke [$NOTIFY_URL]
--notify.retries= Number of additional retries (default: 5) [$NOTIFY_RETRIES]
--notify.interval= Interval between attempts (default: 12s) [$NOTIFY_INTERVAL]
--notify.method= HTTP method (default: POST) [$NOTIFY_METHOD]
--notify.timeout= Request timeout (default: 30s) [$NOTIFY_TIMEOUT]
--notify.authorization= Authorization header value [$NOTIFY_AUTHORIZATION]
Help Options:
-h, --help Show this help message
```
## Notifications
Scheduler will send notifications after each job if `NOTIFY_URL` env variable or `--notify.url` flag set. Each
notification is a simple HTTP request.
HTTP method, attempts number, and interval between attempts can be configured.
Authorization via `Authorization` header also supported.
Scheduler will stop retries if at least one of the following criteria met:
- reached maximum number of attempts
- server returned any `2xx` code (ex: `200`, `201`, ...)
Outgoing custom headers:
- `Content-Type: application/json`
- `User-Agent: scheduler/`, where `` is build version
- `Authorization: ` (if set)
Payload:
```json
{
"project": "compose-project",
"service": "web",
"container": "deadbeaf1234",
"schedule": "@daily",
"started": "2023-01-20T11:10:39.44006+08:00",
"finished": "2023-01-20T11:10:39.751879+08:00",
"failed": true,
"error": "exit code 1"
}
```
> field `error` exists only if `failed == true`