Worker and enqueuer for Q4M using the interface of ActiveJob.
Add this line to your application's Gemfile:
gem 'shinq'
And then execute:
$ bundle
Or install it yourself as:
$ gem install shinq
Rails.application.configure do
config.active_job.queue_adapter = :shinq
end
$ rails generate shinq:worker worker_name title:string
create db/migrate/20141110061243_create_worker_names.rb
create app/workers/worker_name.rb
Generated worker file (app/workers/worker_name.rb)
class WorkerName < ActiveJob::Base
queue_as :worker_names
def perform(args)
#do something
end
end
Generated migration file
class CreateWorkerNames < ActiveRecord::Migration
def change
create_table :worker_names, id: false, options: "ENGINE=QUEUE" do |t|
t.string :job_id, null: false
t.string :title
t.datetime :enqueued_at, null: false
end
end
end
$ rake db:migrate
== 20141110061243 CreateWorkerNames: migrating ================================
-- create_table(:worker_names, {:id=>false, :options=>"ENGINE=QUEUE"})
-> 0.0260s
== 20141110061243 CreateWorkerNames: migrated (0.0261s) =======================
mysql> show create table worker_names\G
*************************** 1. row ***************************
Table: worker_names
Create Table: CREATE TABLE `worker_names` (
`job_id` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`title` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`enqueued_at` datetime NOT NULL
) ENGINE=QUEUE DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci
WorkerName.perform_later(title: 'foo')
$ bundle exec shinq --worker worker_name
You can specify some options. see bundle exec shinq --help
- Fork it ( https://github.com/ryopeko/shinq/fork )
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
) - Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request