Skip to content

KodepandaID/shigoto

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shigoto - Task Scheduling

GitHub tag (latest by date) GitHub Coverage Status

Shigoto is a task scheduling for Golang with friendly API. Shigoto used MongoDB for persistent storage and used Cron format to set the schedule.

Installation

go get github.com/KodepandaID/shigoto

Example Usage

Init

package main

import "github.com/KodepandaID/shigoto"

func main() {
    client, e := shigoto.New(&shigoto.Config{
		DB:      "mongodb://localhost:27017",
		DBName:  "jobs-scheduler",
        Timezone: "Asia/Jakarta",
	})
    if e != nil {
        log.Fatal(e)
    }

    client.Run()
}

Register a function to call

func main() {
    client, e := shigoto.New(&shigoto.Config{
		DB:      "mongodb://localhost:27017",
		DBName:  "jobs-scheduler",
        Timezone: "Asia/Jakarta",
	})
    if e != nil {
        log.Fatal(e)
    }
    
    client.Register("hello", hello)
    client.Register("hello-params", helloParams, "message here")
    client.Run()
}

func hello() error {
    return nil
}

func helloParams(message string) error {
    return nil
}

Set Job

For more scheduling information, you can read at Go References.

func main() {
    client, e := shigoto.New(&shigoto.Config{
		DB:      "mongodb://localhost:27017",
		DBName:  "jobs-scheduler",
        Timezone: "Asia/Jakarta",
	})
    if e != nil {
        log.Fatal(e)
    }
    
    client.Register("hello", hello)
    if _, e := client.
        Command("job-name-here", "hello").
        EveryMinute().Do(); e != nil {
        log.Fatal(e)
    }
    client.Run()
}

func hello() error {
    return nil
}

Remove a Job

func main() {
    client, e := shigoto.New(&shigoto.Config{
		DB:      "mongodb://localhost:27017",
		DBName:  "jobs-scheduler",
        Timezone: "Asia/Jakarta",
	})
    if e != nil {
        log.Fatal(e)
    }
    
    client.Register("hello", hello)
    client.Delete("hello")
    client.Run()
}

License

Copyright Yudha Pratama Wicaksana, Licensed under MIT.