crontask

command module
v0.0.0-...-e675862 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 18, 2016 License: MIT Imports: 10 Imported by: 0

README

CronTask

It's a simple job scheduler with HTTP interface and MySQL as Database.

Setting

You can install this server with this command:

go get github.com/khoa-le/crontask

Browse to the guartz directory and install the dependencies:

godep restore

Build the binary:

go build

This will create a binary called guartz, create the a .env file on the root of the project with this content:

MYSQL_DB=root:password@tcp(127.0.0.1:3306)/crontask?charset=utf8&parseTime=True
GIN_MODE=prod
PORT=8081

And set the enviroment variable:

export GUARTZ_MODE=dev

Now you can run the server:

./crontask

This will run the server where you will be able to schedule the command's execution in the operative system.

API REST

You can manage the tasks on the server by

Creating a task

You can create a task on the server with this rest call

POST http://localhost:3000/tasks
{
    "id": "task-id",
    "periodicity": "@every 1h",
    "command": "docker run demoApp"
}

With this request I can create a task that will run a docker container every hour. You can use any cron unix valid format or use these shortcuts:

Entry                  | Description                                | Equivalent To
-----                  | -----------                                | -------------
@yearly (or @annually) | Run once a year, midnight, Jan. 1st        | 0 0 0 1 1 *
@monthly               | Run once a month, midnight, first of month | 0 0 0 1 * *
@weekly                | Run once a week, midnight on Sunday        | 0 0 0 * * 0
@daily (or @midnight)  | Run once a day, midnight                   | 0 0 0 * * *
@hourly                | Run once an hour, beginning of hour        | 0 0 * * * *

The server uses https://godoc.org/gopkg.in/robfig/cron.v2 library, there you can get more information.

Stopping a task

You can stop a task by deleting it or updating it:

DELETE http://localhost:3000/tasks/task-id
POST http://localhost:3000/tasks
{
    "id": "task-id",
    "periodicity": "stop",
    "command": "docker run demoApp"
}

Listing tasks

You can list all system tasks:

GET http://localhost:3000/tasks

Get a task

You can show the info of a task using:

GET http://localhost:3000/tasks/task-id

Feel free to contribute and report bugs.

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
Godeps
_workspace/src/github.com/go-sql-driver/mysql
Go MySQL Driver - A MySQL-Driver for Go's database/sql package The driver should be used via the database/sql package: import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname") See https://github.com/go-sql-driver/mysql#usage for details
Go MySQL Driver - A MySQL-Driver for Go's database/sql package The driver should be used via the database/sql package: import "database/sql" import _ "github.com/go-sql-driver/mysql" db, err := sql.Open("mysql", "user:password@/dbname") See https://github.com/go-sql-driver/mysql#usage for details
_workspace/src/github.com/joho/godotenv
Package godotenv is a go port of the ruby dotenv library (https://github.com/bkeepers/dotenv) Examples/readme can be found on the github page at https://github.com/joho/godotenv The TL;DR is that you make a .env file that looks something like SOME_ENV_VAR=somevalue and then in your go code you can call godotenv.Load() and all the env vars declared in .env will be avaiable through os.Getenv("SOME_ENV_VAR")
Package godotenv is a go port of the ruby dotenv library (https://github.com/bkeepers/dotenv) Examples/readme can be found on the github page at https://github.com/joho/godotenv The TL;DR is that you make a .env file that looks something like SOME_ENV_VAR=somevalue and then in your go code you can call godotenv.Load() and all the env vars declared in .env will be avaiable through os.Getenv("SOME_ENV_VAR")
_workspace/src/github.com/qor/inflection
Package inflection pluralizes and singularizes English nouns.
Package inflection pluralizes and singularizes English nouns.
_workspace/src/github.com/rifflock/lfshook
Package LFShook allows users to write to the logfiles using logrus.
Package LFShook allows users to write to the logfiles using logrus.
_workspace/src/golang.org/x/net/context
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
Package context defines the Context type, which carries deadlines, cancelation signals, and other request-scoped values across API boundaries and between processes.
_workspace/src/gopkg.in/bluesuncorp/validator.v5
Package validator implements value validations for structs and individual fields based on tags.
Package validator implements value validations for structs and individual fields based on tags.
_workspace/src/gopkg.in/bluesuncorp/validator.v6
Package validator implements value validations for structs and individual fields based on tags.
Package validator implements value validations for structs and individual fields based on tags.
_workspace/src/gopkg.in/robfig/cron.v2
Package cron implements a cron spec parser and runner.
Package cron implements a cron spec parser and runner.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL