shinq 0.0.1.alpha1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3dc7ce36cb2fc9173d2ba088c3a6786adf715318
4
+ data.tar.gz: b3230473df8c6a018af822d8f596c0643565b455
5
+ SHA512:
6
+ metadata.gz: 5a684c09a3e04352ab2186b70c50b5f12f5d2c1fa189bd050bf225819255fa999ca33c7667d49c956d96c6f2452bddbe8b153ed3fe33bde1bdd436d42c48c29b
7
+ data.tar.gz: eb33a3f9c85156db99f1ab4bf2a9f3fe89210505395487deaba696d286cb23ac24090c387d7c8079577048604da5bb374aa64c8f17d0c65673705a753bc2fc34
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in shinq.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ryoichi SEKIGUCHI
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,57 @@
1
+ # Shinq
2
+
3
+ Worker and enqueuer for Q4M using the interface of ActiveJob.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'shinq'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install shinq
20
+
21
+ [Install Q4M](http://q4m.github.io/install.html)
22
+
23
+ ## Usage
24
+
25
+ ### Initialize
26
+ ```ruby
27
+ Rails.application.configure do
28
+ config.active_job.queue_adapter = :shinq
29
+ end
30
+ ```
31
+
32
+ ### Worker
33
+ ```ruby
34
+ class FooWorker < ActiveJob::Base
35
+ aueue_as :my_queues #name of queue table
36
+
37
+ def perform(args)
38
+ #perform asynchronous
39
+ end
40
+ end
41
+ ```
42
+
43
+ ### Enqueue
44
+ ```ruby
45
+ FooWorker.perform_later(foo: 'bar', baz: 'qux')
46
+ ```
47
+
48
+ ### Worker execution
49
+ TBD
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/[my-github-username]/shinq/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/shinq ADDED
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../lib/shinq/cli'
4
+
5
+ Shinq::CLI.new.run
6
+
7
+
@@ -0,0 +1,11 @@
1
+ module ActiveJob
2
+ module QueueAdapters
3
+ class ShinqAdapter
4
+ class << self
5
+ def enqueue(job)
6
+ Shinq::Client.enqueue(table_name: job.queue_name, args: job.arguments)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
data/lib/shinq/cli.rb ADDED
@@ -0,0 +1,66 @@
1
+ require 'optparse'
2
+ require 'yaml'
3
+ require 'shinq'
4
+ require 'shinq/launcher'
5
+
6
+ module Shinq
7
+ class OptionParseError < StandardError; end
8
+
9
+ class CLI
10
+ def initialize(args=ARGV)
11
+ parse_options(args)
12
+ setup_db_config
13
+ bootstrap
14
+ end
15
+
16
+ def parse_options(args)
17
+ @opts = {}
18
+ parser = OptionParser.new do |opt|
19
+ opt.on('--worker VALUE') do |v|
20
+ @opts[:worker_name] = v
21
+ end
22
+
23
+ opt.on('--db-config VALUE') do |v|
24
+ raise OptionParseError, "#{v} does not exist" unless File.exist?(v)
25
+ @opts[:db_config] = YAML.load_file(v)
26
+ end
27
+
28
+ opt.on('--queue-database VALUE') do |v|
29
+ raise OptionParseError, "#{v}'s settings does not exist" unless @opts[:db_config][v]
30
+ @opts[:queue_db] = v
31
+ @opts[:queue_db_settings] = @opts[:db_config][v]
32
+ end
33
+
34
+ opt.on('--require VALUE') do |v|
35
+ @opts[:require] = v
36
+ end
37
+ end
38
+
39
+ parser.parse!(args)
40
+ @opts
41
+ end
42
+
43
+ def setup_db_config
44
+ Shinq.default_db = @opts[:queue_db]
45
+ Shinq.db_config = @opts[:db_config]
46
+ end
47
+
48
+ def bootstrap
49
+ return unless @opts[:require]
50
+
51
+ if File.directory?(@opts[:require])
52
+ require 'rails'
53
+ require File.expand_path("#{@opts[:require]}/config/application.rb")
54
+
55
+ require 'shinq/rails'
56
+ require File.expand_path("#{@opts[:require]}/config/environment.rb")
57
+ else
58
+ require @opts[:require]
59
+ end
60
+ end
61
+
62
+ def run
63
+ Shinq::Launcher.new(@opts[:worker_name]).run
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,44 @@
1
+ require 'sql-maker'
2
+
3
+ module Shinq
4
+ class Client
5
+ def self.builder
6
+ @builder ||= SQL::Maker.new(driver: 'mysql')
7
+ end
8
+
9
+ def self.enqueue(table_name: , args:)
10
+ case args
11
+ when Hash
12
+ sql, bind = builder.insert(table_name, args)
13
+ Shinq.connection.xquery(sql, bind)
14
+ when Array
15
+ args.each do |queue|
16
+ sql, bind = builder.insert(table_name, queue)
17
+
18
+ Shinq.connection.xquery(sql, bind)
19
+ end
20
+ else
21
+ raise ArgumentError, "queue should be Array[Hash] or Hash"
22
+ end
23
+ end
24
+
25
+ def self.dequeue(table_name:)
26
+ has_queue = Shinq.connection.xquery('select queue_wait(?)', table_name)
27
+
28
+ if has_queue
29
+ sql = builder.select(table_name, ['*']).first
30
+ results = Shinq.connection.xquery(sql)
31
+ end
32
+
33
+ results.first
34
+ end
35
+
36
+ def self.done
37
+ Shinq.connection.query('select queue_end()')
38
+ end
39
+
40
+ def self.abort
41
+ Shinq.connection.query('select queue_abort()')
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,24 @@
1
+ require 'shinq/client'
2
+ require 'active_support/inflector'
3
+
4
+ module Shinq
5
+ class Launcher
6
+ def initialize(worker_name)
7
+ @worker_name = worker_name
8
+ @worker_class = @worker_name.camelize.constantize
9
+ end
10
+
11
+ def run
12
+ queue = Shinq::Client.dequeue(table_name: @worker_name.pluralize)
13
+
14
+ begin
15
+ @worker_class.new.perform(queue)
16
+ rescue => e
17
+ Shinq::Client.abort
18
+ raise
19
+ end
20
+
21
+ Shinq::Client.done
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ require 'shinq/active_job/queue_adapters/shinq_adapter'
2
+
3
+ module Shinq
4
+ class Rails < ::Rails::Engine
5
+ initializer :shinq do
6
+ Shinq::Rails.rails_bootstrap
7
+ end
8
+
9
+ def self.rails_bootstrap
10
+ Shinq.db_config = ActiveRecord::Base.configurations
11
+ Shinq.default_db = ::Rails.env
12
+ end
13
+ end
14
+ end
data/lib/shinq.rb ADDED
@@ -0,0 +1,35 @@
1
+ require "mysql2-cs-bind"
2
+ require 'shinq/client'
3
+
4
+ module Shinq
5
+ VERSION = Gem.loaded_specs['shinq'].version.to_s
6
+
7
+ def self.db_config=(config)
8
+ @db_config = config
9
+ @connections = {}
10
+ end
11
+
12
+ def self.db_config
13
+ @db_config
14
+ end
15
+
16
+ def self.default_db=(db_name)
17
+ @default_db = db_name
18
+ end
19
+
20
+ def self.default_db
21
+ @default_db || ENV['RACK_ENV'] || ENV['RAILS_ENV']
22
+ end
23
+
24
+
25
+ def self.setup_db_connection(db_name)
26
+ @connection ||= {}
27
+ @connections[db_name] = Mysql2::Client.new(db_config[db_name])
28
+ end
29
+
30
+ def self.connection(db_name: default_db)
31
+ @connections[db_name] ||= setup_db_connection(db_name)
32
+ end
33
+ end
34
+
35
+ require 'shinq/rails' if defined?(::Rails::Engine)
data/shinq.gemspec ADDED
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "shinq"
7
+ spec.version = '0.0.1.alpha1'
8
+ spec.authors = ["Ryoichi SEKIGUCHI"]
9
+ spec.email = ["ryopeko@gmail.com"]
10
+ spec.summary = %q{Worker and enqueuer for Q4M using the interface of ActiveJob.}
11
+ spec.homepage = "https://github.com/ryopeko/shinq"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0")
15
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
+ spec.require_paths = ["lib"]
18
+
19
+ spec.add_development_dependency "bundler", "~> 1.7"
20
+ spec.add_development_dependency "rake", "~> 10.0"
21
+ spec.add_development_dependency "pry"
22
+
23
+ spec.add_dependency "mysql2-cs-bind", "~> 0.0.6"
24
+ spec.add_dependency "sql-maker", "~> 0.0.4"
25
+ spec.add_dependency "activesupport", "~> 4.2.0.beta2"
26
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: shinq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1.alpha1
5
+ platform: ruby
6
+ authors:
7
+ - Ryoichi SEKIGUCHI
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mysql2-cs-bind
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.0.6
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.0.6
69
+ - !ruby/object:Gem::Dependency
70
+ name: sql-maker
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.0.4
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.0.4
83
+ - !ruby/object:Gem::Dependency
84
+ name: activesupport
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 4.2.0.beta2
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 4.2.0.beta2
97
+ description:
98
+ email:
99
+ - ryopeko@gmail.com
100
+ executables:
101
+ - shinq
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - Gemfile
107
+ - LICENSE.txt
108
+ - README.md
109
+ - Rakefile
110
+ - bin/shinq
111
+ - lib/shinq.rb
112
+ - lib/shinq/active_job/queue_adapters/shinq_adapter.rb
113
+ - lib/shinq/cli.rb
114
+ - lib/shinq/client.rb
115
+ - lib/shinq/launcher.rb
116
+ - lib/shinq/rails.rb
117
+ - shinq.gemspec
118
+ homepage: https://github.com/ryopeko/shinq
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">"
134
+ - !ruby/object:Gem::Version
135
+ version: 1.3.1
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.2.2
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: Worker and enqueuer for Q4M using the interface of ActiveJob.
142
+ test_files: []