order_up 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e0392de83ad625960ba348387295c0b7e0422d3f
4
+ data.tar.gz: 150b6ec39d532ce066e03c412b4b375f49cf42a9
5
+ SHA512:
6
+ metadata.gz: 78e7fd477baab3081fb0613fe9200947cc05310b795dfeab401a97f0bcafa01ff565e9db36e9fac1da3377a234a899df7315d42b831009df04be87fce1ca3218
7
+ data.tar.gz: 1f96da7e4f6fbacca7c99086b3cfce234c526cf24378d177a375278c041011fff8a69027e2bda9badeec595f53ae41b8e00f9392a5452893acd6a6323b7c1c38
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format progress
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in hydra-queue.gemspec
4
+ gemspec
@@ -0,0 +1,15 @@
1
+ ##########################################################################
2
+ # Copyright 2014 Data Curation Experts
3
+ # Additional copyright may be held by others, as reflected in the commit log
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
@@ -0,0 +1,83 @@
1
+ # OrderUp
2
+
3
+ A queue agnostic interface for Rails. Currently only Resque is supported, but we'd like to add other implementations if you want to contribute one.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'order_up'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install order_up
18
+
19
+ ## Usage
20
+
21
+ Create a config file: `config/resque.yml`
22
+
23
+ ```yaml
24
+ development: localhost:6379
25
+ test: localhost:6379
26
+ production: redis1.ae.github.com:6379
27
+ ```
28
+
29
+ Then make an initializer that reads the yaml file and sets up Resque:
30
+
31
+ ```ruby
32
+ # config/initializers/resque.rb
33
+ rails_root = ENV['RAILS_ROOT'] || File.dirname(__FILE__) + '/../..'
34
+ rails_env = ENV['RAILS_ENV'] || 'development'
35
+
36
+ config = YAML::load_file(rails_root + '/config/resque.yml')
37
+ Resque.redis = config[rails_env]
38
+
39
+ Resque.inline = rails_env == 'test'
40
+ Resque.redis.namespace = "myproject:#{rails_env}"
41
+ ```
42
+
43
+ Now you can push jobs into the queue:
44
+ ```ruby
45
+ class MyJob
46
+ def initialize(file_id, message)
47
+ @file_id = file_id
48
+ @message = message
49
+ end
50
+
51
+ def run
52
+ File.find(@file_id).deliver(@message)
53
+ end
54
+ end
55
+
56
+ my_job = MyJob.new(123, "It works!")
57
+ OrderUp.push(my_job)
58
+ ```
59
+
60
+ The initalizer will be called when the job is created, and the `run` method
61
+ will be invoked when the job is processed asynchronously.
62
+
63
+ ### Running the background workers
64
+ First add to your `Rakefile`
65
+ ```ruby
66
+ require 'resque/tasks'
67
+ ```
68
+ Then you can invoke the rake task:
69
+
70
+ ```bash
71
+ $ QUEUE=* rake environment resque:work
72
+ ```
73
+
74
+ ### See also
75
+ (https://github.com/resque/resque/tree/1-x-stable)
76
+
77
+ ## Contributing
78
+
79
+ 1. Fork it ( http://github.com/<my-github-username>/order_up/fork )
80
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
81
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
82
+ 4. Push to the branch (`git push origin my-new-feature`)
83
+ 5. Create new Pull Request
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec) do |config|
5
+ end
@@ -0,0 +1,28 @@
1
+ require 'resque'
2
+ require 'active_support'
3
+ module OrderUp
4
+ extend ActiveSupport::Autoload
5
+ autoload :Resque
6
+ def self.config
7
+ @@config ||= Configuration.new
8
+ yield @@config if block_given?
9
+ return @@config
10
+ end
11
+
12
+ def self.push(val)
13
+ instance.push(val)
14
+ end
15
+
16
+ private
17
+ def self.instance
18
+ @@instance ||= config.queue.new('hydra')
19
+ end
20
+
21
+ class Configuration
22
+ attr_writer :queue
23
+
24
+ def queue
25
+ @queue || OrderUp::Resque
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,40 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext/string/inflections'
3
+ require 'active_support/json/encoding' # in rails 4.0
4
+ #require 'active_support/core_ext/object/json' # in rails 4.1
5
+ module OrderUp
6
+ class Resque
7
+ attr_reader :default_queue_name
8
+
9
+ ENCAPSULATED_CLASS = "_encapsulated_class".freeze
10
+
11
+ def initialize(default_queue_name)
12
+ @default_queue_name = default_queue_name
13
+ end
14
+
15
+ def push(job)
16
+ queue = job.respond_to?(:queue_name) ? job.queue_name : default_queue_name
17
+ # this can raise a Redis::CannotConnectError
18
+ ::Resque.enqueue_to queue, JsonJob, JsonJob.serialize(job)
19
+ end
20
+
21
+ class JsonJob
22
+ def self.perform(job_data)
23
+ deserialize(job_data).run
24
+ end
25
+ def self.serialize(job)
26
+ job.as_json.merge(ENCAPSULATED_CLASS => job.class.name).to_json
27
+ end
28
+
29
+ def self.deserialize(job_data)
30
+ data = JSON.parse(job_data)
31
+ class_name = data.delete(ENCAPSULATED_CLASS)
32
+ class_name.constantize.allocate.tap do |obj|
33
+ data.each do |key, value|
34
+ obj.instance_variable_set(:"@#{key}", value)
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,3 @@
1
+ module OrderUp
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'order_up/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "order_up"
8
+ spec.version = OrderUp::VERSION
9
+ spec.authors = ["Justin Coyne"]
10
+ spec.email = ["justin@curationexperts.com"]
11
+ spec.summary = %q{Backend agnostic queuing implementation}
12
+ spec.description = %q{Backend agnostic queuing implementation}
13
+ spec.homepage = "http://projecthydra.org"
14
+ spec.license = "APACHE2"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "resque", "~>1.25"
22
+ spec.add_dependency "activesupport"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.5"
25
+ spec.add_development_dependency "rake"
26
+ spec.add_development_dependency "rspec"
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+ require 'active_support/core_ext/class/attribute'
3
+
4
+ describe OrderUp do
5
+ before do
6
+ OrderUp.config do |config|
7
+ config.queue = OrderUp::Resque
8
+ end
9
+ end
10
+ class TestJob
11
+ class_attribute :worked
12
+ attr_accessor :name
13
+
14
+ def initialize(name)
15
+ self.name = name
16
+ end
17
+
18
+ def run
19
+ self.class.worked = name
20
+ end
21
+ end
22
+ it "should do work in the background" do
23
+ OrderUp.push TestJob.new('test message')
24
+ TestJob.worked.should == 'test message'
25
+
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ require 'order_up'
2
+
3
+ Resque.inline = true
4
+ RSpec.configure do |config|
5
+ # config.treat_symbols_as_metadata_keys_with_true_values = true
6
+ # config.run_all_when_everything_filtered = true
7
+ # config.filter_run :focus
8
+
9
+ # Run specs in random order to surface order dependencies. If you find an
10
+ # order dependency and want to debug it, you can fix the order by providing
11
+ # the seed, which is printed after each run.
12
+ # --seed 1234
13
+ config.order = 'random'
14
+ end
metadata ADDED
@@ -0,0 +1,129 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: order_up
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Justin Coyne
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: resque
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.25'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.25'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Backend agnostic queuing implementation
84
+ email:
85
+ - justin@curationexperts.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - Gemfile
93
+ - LICENSE.txt
94
+ - README.md
95
+ - Rakefile
96
+ - lib/order_up.rb
97
+ - lib/order_up/resque.rb
98
+ - lib/order_up/version.rb
99
+ - order_up.gemspec
100
+ - spec/lib/hydra/queue_spec.rb
101
+ - spec/spec_helper.rb
102
+ homepage: http://projecthydra.org
103
+ licenses:
104
+ - APACHE2
105
+ metadata: {}
106
+ post_install_message:
107
+ rdoc_options: []
108
+ require_paths:
109
+ - lib
110
+ required_ruby_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - '>='
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ required_rubygems_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - '>='
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ requirements: []
121
+ rubyforge_project:
122
+ rubygems_version: 2.1.11
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Backend agnostic queuing implementation
126
+ test_files:
127
+ - spec/lib/hydra/queue_spec.rb
128
+ - spec/spec_helper.rb
129
+ has_rdoc: