Code Monkey home page Code Monkey logo

rooster's Introduction

rooster

Rooster is a job scheduler that runs in multiple queues with jobs being executed in parallel.

How to use

import "github.com/arkadyb/rooster"

Create new rooster

To create new rooster item use NewRooster function that takes two arguments - selector and queues where selector is function of type QueueSelectorFunc that describes a way next execution queue is selected for a new scheduled job.

You may define your own QueueSelectorFunc to select queue depending on content of your job or scheduler. A simple Round Robin selector may look like

roundRobinSelector:=func() rooster.QueueSelectorFunc {
    selectedQueueIndex := 0
    return func(queues []*rooster.Queue) *rooster.Queue {
        q := queues[selectedQueueIndex]

        selectedQueueIndex++
        if selectedQueueIndex >= len(queues) {
            selectedQueueIndex = 0
        }

        return q
    }
}

Queues are the workload chains that store and execute jobs. User rooster.NewQueue() function to create new queue.

scheduler:=rooster.NewRooster(roundRobinSelector, []*rooster.Queue{rooster.NewQueue(), rooster.NewQueue()})

Here rooster would be created with two execution queues with one being selected to run scheduled job in round robin style.

Schedule job

Rooster exposes Enqueue function to schedule new job and Dequeue to remove job before its being executed. Use rooster.NewJob() function to create a new job. Function takes two arguments - time when job should be executed and JobFunc.

scheduler.Enqueue(NewJob(time.Now().Add(5 * time.Second), func(j *Job){
    fmt.Printf("Job %s has been executed\n", j.GetID())
}))

Middleware

Interceptors may be included into execution chain for given Queue. Specify interceptor functions when creating new queue

NewQueue(func(job Job){
    fmt.Printf("First interceptor run for job %s\n", job.GetID())
}, func(job Job){
    fmt.Printf("Second interceptor run for job %s\n", job.GetID())
})

License

The MIT License (MIT)

rooster's People

Contributors

arkadyb avatar

Watchers

 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.