Convert Figma logo to code with AI

bamzi logojobrunner

Framework for performing work asynchronously, outside of the request flow

1,058
98
1,058
11

Top Related Projects

3,669

Build desktop applications in Go and HTML.

5,869

Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron

13,186

a cron library for go

10,236

Simple, reliable, and efficient distributed task queue in Go

Quick Overview

JobRunner is a lightweight, concurrent job scheduling library for Go. It allows developers to easily create and manage background jobs, with features like automatic retries, job prioritization, and concurrent execution.

Pros

  • Simple and intuitive API for job scheduling and management
  • Supports concurrent job execution with customizable worker pools
  • Provides automatic retry functionality for failed jobs
  • Allows job prioritization and scheduling at specific times

Cons

  • Limited documentation and examples
  • No built-in persistence for job queues (in-memory only)
  • Lacks advanced features like distributed job processing
  • Not actively maintained (last commit was over 3 years ago)

Code Examples

Creating and running a simple job:

job := jobrunner.New("simple-job", func() {
    fmt.Println("Hello from JobRunner!")
})
jobrunner.Run(job)

Scheduling a job to run at a specific time:

job := jobrunner.New("scheduled-job", func() {
    fmt.Println("This job runs at a specific time!")
})
jobrunner.Schedule("0 0 * * *", job) // Run daily at midnight

Creating a job with retry functionality:

job := jobrunner.New("retry-job", func() {
    // Simulating a failure
    if rand.Float32() < 0.5 {
        panic("Job failed!")
    }
    fmt.Println("Job succeeded!")
}).RetryTimes(3)
jobrunner.Run(job)

Getting Started

To use JobRunner in your Go project, first install it using:

go get github.com/bamzi/jobrunner

Then, import it in your Go code:

import "github.com/bamzi/jobrunner"

Create a simple job and run it:

func main() {
    job := jobrunner.New("example-job", func() {
        fmt.Println("Job is running!")
    })
    jobrunner.Run(job)
}

This will create a new job named "example-job" and run it immediately. You can customize job behavior, add scheduling, and implement more complex job logic as needed.

Competitor Comparisons

3,669

Build desktop applications in Go and HTML.

Pros of Gallium

  • Focuses on building desktop applications with Go and HTML/CSS/JavaScript
  • Provides a more comprehensive framework for creating cross-platform desktop apps
  • Offers better integration with native OS features and UI elements

Cons of Gallium

  • Steeper learning curve due to its more complex architecture
  • Less active development and community support compared to JobRunner
  • May be overkill for simple background job processing tasks

Code Comparison

Gallium (app initialization):

package main

import "github.com/alexflint/gallium"

func main() {
    gallium.Loop(func(app *gallium.App) {
        app.NewWindow("http://example.com/")
    })
}

JobRunner (job definition):

package main

import "github.com/bamzi/jobrunner"

type GreetingJob struct {
    Name string
}

func (g GreetingJob) Run() {
    fmt.Printf("Hello, %s!\n", g.Name)
}

Summary

Gallium is better suited for building full-fledged desktop applications with rich user interfaces, while JobRunner is more focused on managing and scheduling background jobs. Gallium offers more features for creating cross-platform desktop apps, but comes with increased complexity. JobRunner, on the other hand, provides a simpler solution for running scheduled tasks and background jobs in Go applications.

5,869

Easy and fluent Go cron scheduling. This is a fork from https://github.com/jasonlvhit/gocron

Pros of gocron

  • More active development with frequent updates and contributions
  • Supports concurrent job execution
  • Offers more scheduling options, including cron expressions

Cons of gocron

  • Slightly more complex API compared to jobrunner
  • May have a steeper learning curve for beginners

Code Comparison

jobrunner:

job := jobrunner.New()
job.Every(5 * time.Minute)
job.Do(myFunction)

gocron:

s := gocron.NewScheduler(time.UTC)
s.Every(5).Minutes().Do(myFunction)
s.StartAsync()

Both libraries provide simple ways to schedule jobs, but gocron offers more flexibility in scheduling options and supports concurrent execution. jobrunner has a simpler API, which may be preferable for basic use cases.

gocron is more actively maintained and has a larger community, which can be beneficial for long-term support and feature additions. However, jobrunner's simplicity might be advantageous for smaller projects or those new to job scheduling in Go.

When choosing between the two, consider your project's complexity, required scheduling features, and your team's familiarity with job scheduling concepts.

13,186

a cron library for go

Pros of cron

  • More mature and widely used project with a larger community
  • Supports more complex scheduling patterns using cron syntax
  • Provides built-in logging and error handling mechanisms

Cons of cron

  • Heavier and more complex implementation
  • May be overkill for simple job scheduling needs

Code Comparison

jobrunner:

job := jobrunner.New()
job.Every(5).Minutes().Run(myFunction)

cron:

c := cron.New()
c.AddFunc("*/5 * * * *", myFunction)
c.Start()

Summary

jobrunner is a lightweight job scheduling library for Go, focusing on simplicity and ease of use. It provides a fluent API for scheduling recurring tasks but has limited features compared to more robust solutions.

cron is a more comprehensive job scheduling library that offers advanced scheduling capabilities using cron syntax. It's better suited for complex scheduling needs and provides additional features like logging and error handling.

While jobrunner is simpler to set up and use for basic tasks, cron offers more flexibility and power for managing complex job schedules. The choice between the two depends on the specific requirements of your project and the level of scheduling complexity you need to handle.

10,236

Simple, reliable, and efficient distributed task queue in Go

Pros of Asynq

  • More active development with frequent updates and releases
  • Extensive documentation and examples for various use cases
  • Built-in support for Redis Cluster and Redis Sentinel

Cons of Asynq

  • Steeper learning curve due to more advanced features
  • Requires Redis as a dependency, which may not be suitable for all projects

Code Comparison

Jobrunner:

job := jobrunner.New()
job.AddFunc("@every 5s", myFunc)
job.Start()

Asynq:

client := asynq.NewClient(asynq.RedisClientOpt{Addr: redisAddr})
task := asynq.NewTask("send_email", payload)
_, err := client.Enqueue(task)

Both libraries offer job scheduling capabilities, but Asynq provides more advanced features and flexibility. Jobrunner focuses on simplicity and ease of use, while Asynq offers a more robust solution with Redis integration.

Asynq supports distributed task processing, periodic tasks, and advanced queue management. It also provides better error handling and retry mechanisms. However, this comes at the cost of increased complexity and the requirement of Redis.

Jobrunner, on the other hand, is more lightweight and doesn't require additional dependencies. It's suitable for simpler use cases and projects that don't need distributed task processing.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

JobRunner

JobRunner is framework for performing work asynchronously, outside of the request flow. It comes with cron to schedule and queue job functions for processing at specified time.

It includes a live monitoring of current schedule and state of active jobs that can be outputed as JSON or Html template.

Install

go get github.com/bamzi/jobrunner

Setup

package main

import "github.com/bamzi/jobrunner"

func main() {
    jobrunner.Start() // optional: jobrunner.Start(pool int, concurrent int) (10, 1)
    jobrunner.Schedule("@every 5s", ReminderEmails{})
}

// Job Specific Functions
type ReminderEmails struct {
    // filtered
}

// ReminderEmails.Run() will get triggered automatically.
func (e ReminderEmails) Run() {
    // Queries the DB
    // Sends some email
    fmt.Printf("Every 5 sec send reminder emails \n")
}

Live Monitoring


// Example of GIN micro framework
func main() {
    routes := gin.Default()

    // Resource to return the JSON data
    routes.GET("/jobrunner/json", JobJson)

    // Load template file location relative to the current working directory
    routes.LoadHTMLGlob("../github.com/bamzi/jobrunner/views/Status.html")

    // Returns html page at given endpoint based on the loaded
    // template from above
    routes.GET("/jobrunner/html", JobHtml)

    routes.Run(":8080")
}

func JobJson(c *gin.Context) {
    // returns a map[string]interface{} that can be marshalled as JSON
    c.JSON(200, jobrunner.StatusJson())
}

func JobHtml(c *gin.Context) {
    // Returns the template data pre-parsed
    c.HTML(200, "", jobrunner.StatusPage())

}

WHY?

To reduce our http response latency by 200+%

JobRunner was created to help us process functions unrelated to response without any delays to the http response. GoRoutines would timeout because response has already been processed, closing the instance window all together.

Instead of creating a separate independent app, we wanted to save time and manageability of our current app by coupling-in the job processing. We did not want to have micro services. It's premature optimization.

If you have a web app or api service backend and want a job processing framework built into your app then JobRunner is for you. Once you hit mass growth and need to scale, you can simply decouple you JobRunners into a dedicated app.

Use cases

Here are some examples of what we use JobRunner for:

  • Send emails to new users after signup
  • Sending push notification or emails based on specifics
  • ReMarketing Engine - send invites, reminder emails, etc ...
  • Clean DB, data or AMZ S3
  • Sending Server stats to monitoring apps
  • Send data stats at daily or weekly intervals

Supported Featured

All jobs are processed outside of the request flow

  • Now: process a job immediately
  • In: processing a job one time, after a given time
  • Every: process a recurring job after every given time gap
  • Schedule: process a job (recurring or otherwise) at a given time

Compatibility

JobRunner is designed to be framework agnostic. So it will work with pure Go apps as well as any framework written in Go Language.

Verified Supported Frameworks

  • Gin
  • Echo
  • Martini
  • Beego
  • Revel (JobRunner is modified version of revel's Jobs module)
  • ...

Examples & recipes are coming soon

Basics

    jobrunner.Schedule("* */5 * * * *", DoSomething{}) // every 5min do something
    jobrunner.Schedule("@every 1h30m10s", ReminderEmails{})
    jobrunner.Schedule("@midnight", DataStats{}) // every midnight do this..
    jobrunner.Every(16*time.Minute, CleanS3{}) // evey 16 min clean...
    jobrunner.In(10*time.Second, WelcomeEmail{}) // one time job. starts after 10sec
    jobrunner.Now(NowDo{}) // do the job as soon as it's triggered

More Detailed CRON Specs

Contribute

Use issues for everything

  • Report problems
  • Discuss before sending pull request
  • Suggest new features
  • Improve/fix documentation

Credits

Author

Bam Azizi Github: @bamzi Twitter: @bamazizi

License

MIT