Skip to content
Snippets Groups Projects

Job Queues

Overview

These jobQueue library written in Go provides a simple interface for managing jobs and workers. It is designed to be used in a distributed environment where multiple workers can be assigned to a job queue. The library provides a Manager that can be used to manage workers, schedule jobs, and handle the state of the job queue.

Jobs can also be persisted to a database using Gorm.

The library also provides a Cron instance for scheduling jobs.

Getting Started

Prerequisites

  • Go 1.22+

Installation

go get -u gitlab.schukai.com/oss/libraries/go/services/job-queues

Usage

Import the package and create a new queue.

import "gitlab.schukai.com/oss/libraries/go/services/job-queues"


func main() {
    var err error
    
    m := jobqueue.NewManager()
    w := jobqueue.NewWorker("worker1")
    _ = m.AddWorker(w)
    
    _ = m.Start()
    
    job := jobqueue.Job{
        ID: "job1",
    }
    scheduler := jobqueue.InstantScheduler{}
    
    _ = m.ScheduleJob(job, &scheduler)
    
}

Tests

Run tests using:

task test

License

This project is licensed under the AGPL-3.0 License - see the LICENSE.md file for details.

Contact