"fmt" "os/exec" "strconv" "strings" "sync" "time" "github.com/ajvb/kala/utils/iso8601" "github.com/ajvb/kala/utils/logging" "github.com/mattn/go-shellwords" "github.com/nu7hatch/gouuid" ) var ( log = logging.GetLogger("kala.job") shParser = shellwords.NewParser() ) func init() { shParser.ParseEnv = true shParser.ParseBacktick = true } type Job struct { Name string `json:"name"` Id string `json:"id"` // Command to run // e.g. "bash /path/to/my/script.sh"
package boltdb import ( "bytes" "encoding/gob" "strings" "time" "github.com/ajvb/kala/job" "github.com/ajvb/kala/utils/logging" "github.com/boltdb/bolt" ) var ( log = logging.GetLogger("kala.job.storage") jobBucket = []byte("jobs") ) func GetBoltDB(path string) *BoltJobDB { if path != "" && !strings.HasSuffix(path, "/") { path += "/" } path += "jobdb.db" database, err := bolt.Open(path, 0600, &bolt.Options{Timeout: time.Second * 10}) if err != nil { log.Fatal(err) } return &BoltJobDB{ path: path,
import ( "fmt" "os" "runtime" "time" "github.com/ajvb/kala/api" "github.com/ajvb/kala/job" "github.com/ajvb/kala/utils/logging" "github.com/codegangsta/cli" ) var ( log = logging.GetLogger("kala") DefaultPersistEvery = 5 * time.Second ) func main() { runtime.GOMAXPROCS(runtime.NumCPU()) app := cli.NewApp() app.Name = "Kala" app.Usage = "Modern job scheduler" app.Version = "0.1" app.Commands = []cli.Command{ { Name: "run", Usage: "run kala", Flags: []cli.Flag{
"github.com/gorilla/mux" ) const ( // Base API v1 Path ApiUrlPrefix = "/api/v1/" JobPath = "job/" ApiJobPath = ApiUrlPrefix + JobPath contentType = "Content-Type" jsonContentType = "application/json;charset=UTF-8" ) var ( log = logging.GetLogger("kala.api") ) type KalaStatsResponse struct { Stats *job.KalaStats } // HandleKalaStatsRequest is the hanlder for getting system-level metrics // /api/v1/stats func HandleKalaStatsRequest(cache job.JobCache) func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) { resp := &KalaStatsResponse{ Stats: job.NewKalaStats(cache), } w.Header().Set(contentType, jsonContentType)
package iso8601 import ( "bytes" "errors" "fmt" "regexp" "strconv" "text/template" "time" "github.com/ajvb/kala/utils/logging" ) var ( log = logging.GetLogger("iso8601") // ErrBadFormat is returned when parsing fails ErrBadFormat = errors.New("bad format string") tmpl = template.Must(template.New("duration").Parse(`P{{if .Years}}{{.Years}}Y{{end}}{{if .Months}}{{.Months}}M{{end}}{{if .Weeks}}{{.Weeks}}W{{end}}{{if .Days}}{{.Days}}D{{end}}{{if .HasTimePart}}T{{end }}{{if .Hours}}{{.Hours}}H{{end}}{{if .Minutes}}{{.Minutes}}M{{end}}{{if .Seconds}}{{.Seconds}}S{{end}}`)) full = regexp.MustCompile(`P((?P<year>\d+)Y)?((?P<month>\d+)M)?((?P<day>\d+)D)?(T((?P<hour>\d+)H)?((?P<minute>\d+)M)?((?P<second>\d+)S)?)?`) week = regexp.MustCompile(`P((?P<week>\d+)W)`) ) type Duration struct { Years int Months int Weeks int Days int