GithubHelp home page GithubHelp logo

bnorton / micro_q Goto Github PK

View Code? Open in Web Editor NEW
7.0 5.0 1.0 1.45 MB

A multi-threaded background queue for Ruby based apps. (single-process mode makes it dev-friendly)

License: MIT License

Ruby 100.00%

micro_q's Introduction

MicroQ

Build Status
Code Climate

MicroQ is a per-process asynchronous background queue.

It's simple startup and intuitive interface makes it the best choice for new and legacy apps.

Installation

Add this line to your Gemfile:

gem 'micro_q'

$ bundle

Or install it:

$ gem install micro_q

Usage

## A typical worker class
class MyWorker
  worker :update # sets up the dsl and adds additional _async methods

  def perform
    # do some performing here
  end

  def update(options = {})
    # do some updating
   end
end

###Simple

# Called on the class invoked on an instance.

MyWorker.perform_async
MyWorker.update_async(:user_id => user.id)

###Advanced

Safely using an ActiveRecord instance via the Custom Loader API

# config/initializers/micro_q
require 'micro_q/methods/active_record'

# app/models/user.rb
class User < Activerecord::Base
  def update_social_data
    # Send HTTP requests to Facebook, Twitter, etc
  end
end

# app/controllers/users_controller.rb
def update
  user = account.users.find(params[:id])
  user.async.update_social_data
end

##Queues By default the queue is an in-memory queue meaning that messages are shared per-process and any unprocessed messages are saved to a file when shutdown occurs.

The Redis queue requires some configuration in your gemfile to keep the runtime dependencies to a minimum

# Gemfile
gem 'redis'
gem 'micro_q'

# config/initializers/micro_q.rb
require 'redis'
require 'micro_q'

# when MicroQ starts simply use the redis queue
MicroQ.configure do |config|
  config.queue = MicroQ::Queue::Redis
end

The Amazon SQS (coming soon) queue require some extra configuration in your gemfile.

# Gemfile
gem 'aws-sdk'
gem 'micro_q'

# config/initializers/micro_q.rb
require 'aws-sdk'
require 'micro_q'

# when MicroQ starts simply use the sqs queue
# this will take care of all other switchover for the system
MicroQ.configure do |config|
  config.queue = MicroQ::Queue::Sqs
  config.aws = { :key => 'YOUR KEY', :secret => 'YOUR SECRET' }
end

Note that when using the SQS Queue only the MicroQ's started via command-line will actually process messages

Start via the command line to process messages microq

This queue also sets up thress named queues :low, :default and :critical

# Then just use the queues in your workers
class SomeWorker
  worker :queue => :critical
end

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

micro_q's People

Contributors

bnorton avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

chordate

micro_q'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.