Git Product home page Git Product logo

cronnie's Introduction

Cronnie Logo

Cronnie

A easy to use but yet powerfull job schedueler written in Go

How does it work?

The basic concept here is the Cronnie connects to a postgres table which it manages itself. by the magic of postgres we can subscribe to the changes on this table, so if a new job is created Cronnie figures out what to do and when to do it

most of the database specific handling is in the db file if you want to deep dive into it. the idea is that Cronnie is fully event based so there is no polling in this code

How to install ?

As with any golang package you can just use the go get command.

go get github.com/xantios/cronnie

How to use ?

For a full code example see example/main.go

JobMaps

Cronie heavily relies on the concept of a JobMap. this is simple a map[string]cronnie.Job a cronnie.Job is a function which excepts a map[string]string A quick example

package main 

func ExampleJobHandler(arg map[string]string) bool {
	// Example 
	return true
}

func main() {
    exampleMap := map[string]Cronnie.Job{
    "example": ExampleJobHandler,
    },
}

Create a config

A simple config can be created using the following snippet

package main

import Cronnie "github.com/xantios/cronnie"

func main() {
	config := &Cronnie.Config{
		Uri: "host=db user=MY_USER password=PASSWORD dbname=app port=5432 sslmode=disable",
		JobMap: map[string]Cronnie.Job{
			"example": ExampleJobHandler,
		},
		Logger: logger,
	}
}

Create a instance

Create a instance to work with, if you have a config this is easy.

cron, err := Cronnie.New(config)

Add a task

To add a task, take the reference created above (or any instance for that matter) and take a look at the following example code. a more involved example can be found in the example directory

	cron.Create("example", map[string]string{
		"arg_1": "This is the first argument",
		"arg_2": "This is the second argument",
	}, time.Time{})

Running job worker

This is where the actual magic happens! Just simply run the Run() function should suffice.

e := cron.Run()

cronnie's People

Watchers

Xantios Krugor avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.