GithubHelp home page GithubHelp logo

iflamed / mfworker Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 32 KB

A memory and file based task worker for Golang. Queue jobs only for single process application.

Go 100.00%
queue queue-workers queued-jobs task-queue worker-queue golang

mfworker's Introduction

Golang mfworker

Mfworker is a memory and file based task worker for Golang. It's embeddable for golang project. So it's only work for single process application.

Features

  1. Custom worker numbers.
  2. Custom the number of jobs stored in memory.
  3. Single process.
  4. Thread safe.
  5. Jobs will be store in memory first, then auto store jobs to badger db file.
  6. Recoverable, when process exit, it will auto save jobs to file.

Demo

package main

import (
    "log"
    "strconv"
    "time"
    "github.com/iflamed/mfworker"
)

func main()  {
    var (
        count    uint
        maxItems uint
    )
    count = 4
    maxItems = 16
    path := "./test.db"
    queueName := "mfworkder"
    q := mfworker.NewQueue(count, maxItems, path, queueName, nil)
    q.Handler("Test", func(job *mfworker.Job) {
        time.Sleep(time.Second)
        log.Printf("the job name %s, job body %s ", job.Name, job.Payload)
    })
    q.Start()
    go func() {
        for i := 0; i < 64; i++ {
            job := &mfworker.Job{
                Name:    "Test",
                Payload: []byte("body " + strconv.Itoa(i)),
            }
            q.Dispatch(job)
        }
    }()
    <-time.After(10 * time.Second)
    q.Stop()
}

mfworker's People

Contributors

iflamed avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  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.