Come up with a name and watch flag
This commit is contained in:
parent
c840d7b0b2
commit
da50191759
20
README.md
20
README.md
@ -1,28 +1,28 @@
|
||||
# docker-batch-scheduler
|
||||
# Dockron
|
||||
|
||||
WIP for a docker batch scheduler
|
||||
A Dead Simple Docker Cron Scheduler
|
||||
|
||||
## Usage
|
||||
|
||||
$APPNAME requires access to the Docker, so it may need to be run as root, or, if in a Docker container, need the socket mapped as a volume.
|
||||
Dockron requires access to the Docker, so it may need to be run as root, or, if in a Docker container, need the socket mapped as a volume.
|
||||
|
||||
### Running $APPNAME
|
||||
### Running Dockron
|
||||
|
||||
As simple as:
|
||||
|
||||
./$APPNAME
|
||||
dockron
|
||||
|
||||
It will then run in the foreground, periodically checking Docker for containers with labels containing a cron schedule.
|
||||
|
||||
$APPNAME will periodically poll Docker for new containers or schedule changes.
|
||||
By default, Dockron will periodically poll Docker for new containers or schedule changes every minute. You can specify an interval by using the `-watch` flag.
|
||||
|
||||
### Scheduling a container
|
||||
|
||||
First, be sure your container is something that is not long running and will actually exit when complete. This is for batch runs and not keeping a service running. Docker should be able to do that on it's own with a restart policy.
|
||||
|
||||
Create your container and add a label in the form `$APPNAME.cron.schedule="* * * * *"`, where the value is a valid cron expression (See the section [Cron Expression Formatting](#cron-expression-formatting)).
|
||||
Create your container and add a label in the form `dockron.schedule="* * * * *"`, where the value is a valid cron expression (See the section [Cron Expression Formatting](#cron-expression-formatting)).
|
||||
|
||||
$APPNAME will now start that container peridically on the schedule.
|
||||
Dockron will now start that container peridically on the schedule.
|
||||
|
||||
### Cron Expression Formatting
|
||||
|
||||
@ -30,7 +30,7 @@ For more information on the cron expression parsing, see the docs for [robfig/cr
|
||||
|
||||
## Caveats
|
||||
|
||||
$APPNAME is quite simple right now. It does not yet:
|
||||
Dockron is quite simple right now. It does not yet:
|
||||
|
||||
* Issue any retries
|
||||
* Cancel hanging jobs
|
||||
@ -40,4 +40,4 @@ I intend to keep it simple as well. It will likely never:
|
||||
* Provide any kind of alerting (check out [Minitor](https://git.iamthefij.com/IamTheFij/minitor))
|
||||
* Handle job dependencies
|
||||
|
||||
Either use a separate tool in conjunction with $APPNAME, or use a more robust scheduler like Tron, or Chronos.
|
||||
Either use a separate tool in conjunction with Dockron, or use a more robust scheduler like Tron, or Chronos.
|
||||
|
12
main.go
12
main.go
@ -1,6 +1,7 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/client"
|
||||
@ -11,10 +12,10 @@ import (
|
||||
)
|
||||
|
||||
// WatchInterval is the duration we should sleep until polling Docker
|
||||
var WatchInterval = (5 * time.Second)
|
||||
var DefaultWatchInterval = (1 * time.Minute)
|
||||
|
||||
// SchedLabel is the string label to search for cron expressions
|
||||
var SchedLabel = "cron.schedule"
|
||||
var SchedLabel = "dockron.schedule"
|
||||
|
||||
// ContainerStartJob represents a scheduled container task
|
||||
// It contains a reference to a client, the schedule to run on, and the
|
||||
@ -78,6 +79,11 @@ func main() {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
// Read interval for polling Docker
|
||||
var watchInterval time.Duration
|
||||
flag.DurationVar(&watchInterval, "watch", DefaultWatchInterval, "Interval used to poll Docker for changes")
|
||||
flag.Parse()
|
||||
|
||||
// Create a Cron
|
||||
c := cron.New()
|
||||
|
||||
@ -99,6 +105,6 @@ func main() {
|
||||
c.Start()
|
||||
|
||||
// Sleep until the next query time
|
||||
time.Sleep(WatchInterval)
|
||||
time.Sleep(watchInterval)
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user