Giter VIP home page Giter VIP logo

gobatch's Introduction

GoBatch

Micro-batching library in Go

Description

This package is a batch processing library. Instead of processing jobs one-by-one, this library groups them into configurable size batches. This is convenient to optimise I/O operations with databases and internet services.

How to Use

This package exposes the Pipe struct which exposes one method: Push(job Job) which returns a pointer to a JobResult. JobResult is a struct which will contain the result of the job once the job has been processed.

Creating a Job:

Call the function NewJob to create a job. The function takes a pointer to the Data which is of type interface{}. The Data is the data which is to be processed.

Using a JobResult:

A JobResult pointer is returned when a job is pushed into the pipe using the Push(job Job) method. To access a JobResult read from the Complete channel. When that channel recieves true, then the job has been completed and the Result member will point to the result.

Creating a BatchProcessor:

In order to configure the pipe a BatchProcessor is required. This is user implemented and the interface is specified in this package. The BatchProcessor must accept an array of Jobs and return an array of BatchResults and an error. If no error is encountered, the error must be nil. BatchResult is a struct containing a pointer to the result. It also contains a member Id which must be set to the Id of the Job to which the BatchResult corresponds.

Configuring the pipe:

To create a pipe, call the function: NewPipe. This function initialises the pipe and configures it using the arguments that it is passed. The following arguments are required:

  • maxDuration: This is the maximum time the pipe should wait before processing a batch
  • maxJobs: This is the maximum number of jobs the pipe should accept before processing a batch
  • batchProcessor: This is the "BatchProcessor" that the pipe will use to process batches

NewPipe returns the created pipe, and an error channel to which any errors will be sent.

Shutting down a pipe

To shutdown a pipe call the Shutdown() method. This will allow all submitted jobs to submit, terminate the pipe and then return.

Building and Testing

Building the library

Navigate to the pipe folder Run the command go build

Running the test suite

Navigate to the pipe folder Run the command go test

gobatch's People

Contributors

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