Code Monkey home page Code Monkey logo

go-batch's Introduction

go-batch

go-batch is a batch processing library written in Go. The process execution has multiple stages to release a Batch to the client.

GitHub top language Go Report Card

Features

  1. Client can use this library as an asynchronous batch processing for their application use case.
  2. There are no restrictions on applying batch processing matrices to the library. The client can define the maximum no of items for a batch using the BatchOptions.
  3. The library has a Workerpool that will faster the batch processing in concurrent scenarios.

Demo

asciicast

Stages

  1. Batch Reader receives the resource payload from the client and marshals the payload item into the BatchItem object.

    type BatchItems struct {
        Id      int
        BatchNo int
        Item    interface{}
    } 
    
    
  2. BatchProducer has a Watcher channel that receives the marshal payload from the Batch reader. Watcher marks each BatchItem with a BatchNo and adds it to the []BatchItems array. After the batch itemCounter++ increases to the MaxItems [DefaultMaxItems: 100], the Batch gets releases to the Consumer callback function.

  3. BatchConsumer has a ConsumerFunc that gets invoke by BatchProducer as a callback function to send the prepared []BatchItems arrays. Then, the Consumer channel sends the []BatchItems to the Worker channel.

  4. Workerline is the sync.WaitGroup synchronizes the workers to send the []BatchItems to the supply chain.

  5. BatchSupplyChannel works as a bidirectional channel that requests for the []BatchItems to the Workerline and gets in the response.

  6. ClientSupplyChannel is the delivery channel that works as a Supply line to sends the []BatchItems and the client receives by listening to the channel.

Go Docs

Documentation at pkg.go.dev

Installation

go get github.com/Deeptiman/go-batch

Example

b := batch.NewBatch(batch.WithMaxItems(100))
go b.StartBatchProcessing()

for i := 1; i <= 1000; i++ {
     b.Item <- &Resources{
         id:   i,
         name: fmt.Sprintf("%s%d", "R-", i),
         flag: false,
     }
 }
b.Close() 

Note

  • In this version release, the library doesn't support starting concurrent BatchProcessing sessions.

License

This project is licensed under the MIT License

go-batch's People

Contributors

deeptiman avatar derblum avatar

Stargazers

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