GithubHelp home page GithubHelp logo

taskqueue's Introduction

Twitter: @taquitos License

TaskQueue

A ruby implementation of a simple dispatch queue using procs

Currently, TaskQueue only has api for dispatching tasks asynchronously.

Example

# Create a queue with as many workers as you want or 1 for a serial queue 
queue = TaskQueue.new(name: 'my concurrent queue', number_of_workers: 5)
task = Task.new(work_block: proc { 
  # some work to be done
})
queue.add_task_async(task: task)
# Or don't supply the number of workers and you'll only get 1, making it a serial queue 
queue = TaskQueue.new(name: 'my serial queue')
task = Task.new(work_block: proc { 
  # some work to be done
})
queue.add_task_async(task: task)

Recreatable Tasks

The tasks that are created from the mixin RecreatableTask can be recovered in future executions of the TaskQueue where their were enqueued originally.

Example

# We define a task that includes RecreatableTask
class HelloToRecreatableTask
  include TaskQueue::RecreatableTask

  # The run! method receives a collection of params and defines the real execution of the task itself.
  def run!(**params)
    puts "Hello #{params}"
  end

  # In case the queue gets deallocated with RecreatableTasks on its queue, the hash returned by this function will be stored. Make sure that all values are JSON encodable.
  def params_to_hash
    { to: "fastlane" }
  end
end

queue = TaskQueue(name: 'test queue')
task = HelloToRecreatableTask.new.to_task
queue.add_task_async(task: task)

Run tests

bundle exec rspec

taskqueue's People

Contributors

krausefx avatar minuscorp avatar snatchev avatar taquitos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

taskqueue's Issues

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.