Gocron manages cron jobs with a configuration.
- docker-compose.yml
services:
gocron:
image: prongbang/gocron:latest
ports:
- "8000:8000"
environment:
- TZ=Asia/Bangkok
POST http://localhost:8000/v1/scheduler
Request
{
"cron": "*/1 * * * *",
"task": {
"type": "api",
"config": {
"url": "http://localhost/notify",
"method": "POST",
"header": {
"X-API-KEY": "ABC"
},
"body": {
"data": "Hi"
}
}
}
}
Response
{
"code": "201",
"message": "Created",
"data": {
"job": "83ba2dc9dd5c4326a07dc9eb2d5163b3"
}
}
GET http://localhost:8000/v1/scheduler
Response
{
"code": "200",
"message": "OK",
"data": [
{
"job": "83ba2dc9dd5c4326a07dc9eb2d5163b3",
"cron": "*/1 * * * *",
"task": {
"type": "api",
"config": {
"url": "http://localhost/notify",
"method": "POST",
"body": {
"data": "Hi"
},
"header": {
"X-API-KEY": "ABC"
}
}
},
"running": true
}
]
}
POST http://localhost:8000/v1/scheduler/stop
Request
{
"job": "83ba2dc9dd5c4326a07dc9eb2d5163b3"
}
Response
{
"code": "200",
"message": "OK",
"data": {
"job": "83ba2dc9dd5c4326a07dc9eb2d5163b3"
}
}
schedulers:
- job: "every-24-hours"
cron: "0 0 * * *"
task:
url: "http://localhost/post"
method: "POST"
body: >
{"data": "every-24-hours"}
header: >
{"X-Api-Key": "XXX"}
- Project structure
project
├── configuration
│ └── configuration.yml
└── docker-compose.yml
- docker-compose.yml
services:
gocron:
image: prongbang/gocron:latest
environment:
- TZ=Asia/Bangkok
- GOCRON_API=true
- GOCRON_BUILDIN=true
- GOCRON_SOURCE=file
volumes:
- "./configuration.yml:/app/configuration/configuration.yml"
- docker-compose.yml
services:
gocron:
image: prongbang/gocron:latest
environment:
- TZ=Asia/Bangkok
- GOCRON_BUILDIN=true
- GOCRON_SOURCE=remote
- GOCRON_REMOTE_SECURE=true
- GOCRON_REMOTE_PROVIDER=http://127.0.0.1:4001
- GOCRON_REMOTE_ENDPOINT=true
- GOCRON_REMOTE_PATH=/config/hugo.yml
- GOCRON_REMOTE_SECRET_KEYRING=/etc/secrets/mykeyring.gpg
- docker-compose.yml
services:
gocron:
image: prongbang/gocron:latest
environment:
- TZ=Asia/Bangkok
- GOCRON_BUILDIN=true
- GOCRON_SOURCE=remote
- GOCRON_REMOTE_SECURE=true
- GOCRON_REMOTE_PROVIDER=http://127.0.0.1:4001
- GOCRON_REMOTE_ENDPOINT=true
- GOCRON_REMOTE_PATH=/config/hugo.yml