superbolt-future 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/.rvmrc +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +1 -0
- data/lib/superbolt/future/app.rb +14 -0
- data/lib/superbolt/future/facade.rb +5 -0
- data/lib/superbolt/future/messenger.rb +31 -0
- data/lib/superbolt/future/runner/requeue.rb +54 -0
- data/lib/superbolt/future/tasks.rb +3 -0
- data/lib/superbolt/future/version.rb +5 -0
- data/lib/superbolt/future.rb +8 -0
- data/lib/tasks/superbolt_future.rake +7 -0
- data/spec/app_spec.rb +74 -0
- data/spec/facade_spec.rb +8 -0
- data/spec/messenger_spec.rb +67 -0
- data/spec/spec_helper.rb +19 -0
- data/superbolt-future.gemspec +26 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 676eb05c0e3b2a66b6fca1cc5689a6d92dd25828
|
4
|
+
data.tar.gz: ed89000383e1cdfcc2885231cd7d49925a44cb88
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 79dc225081883ab2a13070ee81b1e11a858f161a8b2f7142798b9365ba2b20c5772d254981e288d982e31c78eb87a6a8a2cacf9281865419a5d45fa3c1b1e05e
|
7
|
+
data.tar.gz: c5ddcf9bba3a1f5f95a14ba18c680e8ff7b113e5cd62cab8d8b616214c3bcc4f8eecc25cf52311cdd34aa2b95ae80ed5a3261fc149ce89ed6da10666da2c4f9d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rvmrc
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 socialchorus
|
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,29 @@
|
|
1
|
+
# Superbolt::Future
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'superbolt-future'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install superbolt-future
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# This is an extension of the existing Superbolt Messenger class
|
2
|
+
module Superbolt
|
3
|
+
module Future
|
4
|
+
class Messenger < ::Superbolt::Messenger
|
5
|
+
attr_accessor :in_future
|
6
|
+
|
7
|
+
def future!(time, opts=nil)
|
8
|
+
future(time)
|
9
|
+
data(opts)
|
10
|
+
queue.push(message)
|
11
|
+
end
|
12
|
+
|
13
|
+
def future(time)
|
14
|
+
attr_chainer(:in_future, time)
|
15
|
+
end
|
16
|
+
|
17
|
+
def destination_name
|
18
|
+
"#{super}#{future_suffix}"
|
19
|
+
end
|
20
|
+
|
21
|
+
def future_suffix
|
22
|
+
in_future ? '.future' : ''
|
23
|
+
end
|
24
|
+
|
25
|
+
def message
|
26
|
+
hash = super
|
27
|
+
hash.merge({future: in_future})
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Superbolt
|
2
|
+
module Future
|
3
|
+
module Runner
|
4
|
+
class Requeue < ::Superbolt::Runner::AckOne
|
5
|
+
def subscribe
|
6
|
+
queue.subscribe(ack: true) do |delivery_info, metadata, payload|
|
7
|
+
message = Superbolt::IncomingMessage.new(delivery_info, payload, channel)
|
8
|
+
process(message)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def process(message)
|
13
|
+
parsed_message = message.parse
|
14
|
+
requeue(parsed_message)
|
15
|
+
|
16
|
+
message.ack
|
17
|
+
|
18
|
+
block.call(parsed_message, logger) if block
|
19
|
+
sleep sleep_time
|
20
|
+
rescue Exception => e
|
21
|
+
on_error(message.parse, e)
|
22
|
+
end
|
23
|
+
|
24
|
+
def sleep_time
|
25
|
+
0.5 # should this be dynamic?
|
26
|
+
end
|
27
|
+
|
28
|
+
def requeue(parsed_message)
|
29
|
+
time = parsed_message["future"]
|
30
|
+
q = if Time.parse(time) > Time.now
|
31
|
+
logger.info("Requeueing message to #{time}")
|
32
|
+
future_queue
|
33
|
+
else
|
34
|
+
logger.info("Sending message #{parsed_message} to worker queue")
|
35
|
+
worker_queue
|
36
|
+
end
|
37
|
+
q.push(parsed_message)
|
38
|
+
end
|
39
|
+
|
40
|
+
def future_queue
|
41
|
+
Superbolt::Queue.new(queue.name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def worker_queue
|
45
|
+
Superbolt::Queue.new(worker_queue_name)
|
46
|
+
end
|
47
|
+
|
48
|
+
def worker_queue_name
|
49
|
+
queue.name.sub(/\.future$/, '')
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
# assumes an environment task that sets up your app environment
|
2
|
+
desc "spins up process that looks at future queue and moves to the right queue at the right time"
|
3
|
+
task :superbolt_future => :environment do
|
4
|
+
Superbolt::Future::App.new(Superbolt.app_name).run do |message, logger|
|
5
|
+
logger.info('.')
|
6
|
+
end
|
7
|
+
end
|
data/spec/app_spec.rb
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Superbolt::App do
|
4
|
+
let(:app) {
|
5
|
+
Superbolt::Future::App.new(name, {logger: logger})
|
6
|
+
}
|
7
|
+
|
8
|
+
before do
|
9
|
+
future_queue.clear
|
10
|
+
worker_queue.clear
|
11
|
+
Superbolt.env = env
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
future_queue.clear
|
16
|
+
worker_queue.clear
|
17
|
+
end
|
18
|
+
|
19
|
+
let(:env) { 'test' }
|
20
|
+
let(:name) { 'superbolt' }
|
21
|
+
let(:logger) { Logger.new('/dev/null') }
|
22
|
+
|
23
|
+
let(:worker_queue) { Superbolt::Queue.new("#{name}_#{env}") }
|
24
|
+
let(:future_queue) { Superbolt::Queue.new("#{name}_#{env}.future") }
|
25
|
+
let(:quit_queue) { Superbolt::Queue.new("#{name}_#{env}.future.quit") }
|
26
|
+
|
27
|
+
context 'when the future message key is in the past' do
|
28
|
+
let(:message) {
|
29
|
+
{
|
30
|
+
origin: 'origin',
|
31
|
+
event: 'do_something',
|
32
|
+
arguments: {
|
33
|
+
hello: 'developers'
|
34
|
+
},
|
35
|
+
future: Time.now - 3600
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
it "moves the message from the future queue to the worker queue" do
|
40
|
+
future_queue.push(message)
|
41
|
+
|
42
|
+
app.run do |arguments|
|
43
|
+
quit_queue.push({message: 'just because'})
|
44
|
+
end
|
45
|
+
|
46
|
+
worker_queue.size.should == 1
|
47
|
+
future_queue.size.should == 0
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'when the time is in the future' do
|
52
|
+
let(:message) {
|
53
|
+
{
|
54
|
+
origin: 'origin',
|
55
|
+
event: 'do_something',
|
56
|
+
arguments: {
|
57
|
+
hello: 'developers'
|
58
|
+
},
|
59
|
+
future: Time.now + 3600
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
it "puts the message back on the future queue" do
|
64
|
+
future_queue.push(message)
|
65
|
+
|
66
|
+
app.run do |arguments|
|
67
|
+
quit_queue.push({message: 'just because'})
|
68
|
+
end
|
69
|
+
|
70
|
+
worker_queue.size.should == 0
|
71
|
+
future_queue.size.should > 1 # there is a race condition with the quit queue, everything async
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/spec/facade_spec.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Superbolt::Future::Messenger, 'extensions' do
|
4
|
+
let(:messenger) {
|
5
|
+
Superbolt::Future::Messenger.new
|
6
|
+
}
|
7
|
+
|
8
|
+
let(:time) { Time.now + 20 }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Superbolt.env = 'staging'
|
12
|
+
end
|
13
|
+
|
14
|
+
after do
|
15
|
+
Superbolt::Queue.new('advocato_staging.future').clear
|
16
|
+
Superbolt::Queue.new('advocato_staging').clear
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'scheduling in future' do
|
20
|
+
describe '#future!' do
|
21
|
+
it "will send it to the future queue" do
|
22
|
+
messenger.to('advocato').future!(time)
|
23
|
+
Superbolt::Queue.new('advocato_staging.future').size.should == 1
|
24
|
+
end
|
25
|
+
|
26
|
+
it "will send along data if it gets any" do
|
27
|
+
messenger.to('advocato').future!(time, {hello: 'world'})
|
28
|
+
messenger.data.should == {hello: 'world'}
|
29
|
+
end
|
30
|
+
|
31
|
+
it "will not override data if it exists" do
|
32
|
+
messenger.to('advocato').data({what: 'is up?'}).future!(time)
|
33
|
+
messenger.data.should == { what: 'is up?'}
|
34
|
+
end
|
35
|
+
|
36
|
+
it "adds a key to the message about the desired future time" do
|
37
|
+
messenger.to('advocato').future!(time)
|
38
|
+
messenger.message[:future].should == time
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#future' do
|
43
|
+
it "won't send it immediately" do
|
44
|
+
messenger.to('advocato').future(time)
|
45
|
+
Superbolt::Queue.new('advocato_staging.future').size == 0
|
46
|
+
Superbolt::Queue.new('advocato_staging').size == 0
|
47
|
+
end
|
48
|
+
|
49
|
+
it "will send it to the right queue once used" do
|
50
|
+
messenger.to('advocato').future(time).send!({hello: 'Deepti!'})
|
51
|
+
Superbolt::Queue.new('advocato_staging.future').size == 1
|
52
|
+
end
|
53
|
+
|
54
|
+
it "adds a key to the message about the desired future time" do
|
55
|
+
messenger.to('advocato').future(time)
|
56
|
+
messenger.message[:future].should == time
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
describe 'normal usage' do
|
62
|
+
it "will send it to the normal queue" do
|
63
|
+
messenger.to('advocato').send!
|
64
|
+
Superbolt::Queue.new('advocato_staging').size.should == 1
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require_relative '../lib/superbolt/future'
|
8
|
+
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
11
|
+
config.run_all_when_everything_filtered = true
|
12
|
+
config.filter_run :focus
|
13
|
+
|
14
|
+
# Run specs in random order to surface order dependencies. If you find an
|
15
|
+
# order dependency and want to debug it, you can fix the order by providing
|
16
|
+
# the seed, which is printed after each run.
|
17
|
+
# --seed 1234
|
18
|
+
config.order = 'random'
|
19
|
+
end
|
@@ -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
|
+
require 'superbolt/future/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "superbolt-future"
|
8
|
+
spec.version = Superbolt::Future::VERSION
|
9
|
+
spec.authors = ["Deepti Anand", "Kane Baccigalupi", "SocialCoder's at SocialChorus"]
|
10
|
+
spec.email = ["developers@socialchorus.com"]
|
11
|
+
spec.description = %q{Perform superbolt tasks at a later time; timed job queues for the cloud}
|
12
|
+
spec.summary = %q{Perform superbolt tasks at a later time; timed job queues for the cloud}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
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 'superbolt'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: superbolt-future
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Deepti Anand
|
8
|
+
- Kane Baccigalupi
|
9
|
+
- SocialCoder's at SocialChorus
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2014-04-18 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: superbolt
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
requirements:
|
19
|
+
- - '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
requirements:
|
26
|
+
- - '>='
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
version: '0'
|
29
|
+
- !ruby/object:Gem::Dependency
|
30
|
+
name: bundler
|
31
|
+
requirement: !ruby/object:Gem::Requirement
|
32
|
+
requirements:
|
33
|
+
- - ~>
|
34
|
+
- !ruby/object:Gem::Version
|
35
|
+
version: '1.3'
|
36
|
+
type: :development
|
37
|
+
prerelease: false
|
38
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '1.3'
|
43
|
+
- !ruby/object:Gem::Dependency
|
44
|
+
name: rake
|
45
|
+
requirement: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
type: :development
|
51
|
+
prerelease: false
|
52
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
|
+
requirements:
|
54
|
+
- - '>='
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: '0'
|
57
|
+
- !ruby/object:Gem::Dependency
|
58
|
+
name: rspec
|
59
|
+
requirement: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - '>='
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
type: :development
|
65
|
+
prerelease: false
|
66
|
+
version_requirements: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - '>='
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
description: Perform superbolt tasks at a later time; timed job queues for the cloud
|
72
|
+
email:
|
73
|
+
- developers@socialchorus.com
|
74
|
+
executables: []
|
75
|
+
extensions: []
|
76
|
+
extra_rdoc_files: []
|
77
|
+
files:
|
78
|
+
- .gitignore
|
79
|
+
- .rspec
|
80
|
+
- .rvmrc
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE.txt
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- lib/superbolt/future.rb
|
86
|
+
- lib/superbolt/future/app.rb
|
87
|
+
- lib/superbolt/future/facade.rb
|
88
|
+
- lib/superbolt/future/messenger.rb
|
89
|
+
- lib/superbolt/future/runner/requeue.rb
|
90
|
+
- lib/superbolt/future/tasks.rb
|
91
|
+
- lib/superbolt/future/version.rb
|
92
|
+
- lib/tasks/superbolt_future.rake
|
93
|
+
- spec/app_spec.rb
|
94
|
+
- spec/facade_spec.rb
|
95
|
+
- spec/messenger_spec.rb
|
96
|
+
- spec/spec_helper.rb
|
97
|
+
- superbolt-future.gemspec
|
98
|
+
homepage: ''
|
99
|
+
licenses:
|
100
|
+
- MIT
|
101
|
+
metadata: {}
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
112
|
+
requirements:
|
113
|
+
- - '>='
|
114
|
+
- !ruby/object:Gem::Version
|
115
|
+
version: '0'
|
116
|
+
requirements: []
|
117
|
+
rubyforge_project:
|
118
|
+
rubygems_version: 2.0.3
|
119
|
+
signing_key:
|
120
|
+
specification_version: 4
|
121
|
+
summary: Perform superbolt tasks at a later time; timed job queues for the cloud
|
122
|
+
test_files:
|
123
|
+
- spec/app_spec.rb
|
124
|
+
- spec/facade_spec.rb
|
125
|
+
- spec/messenger_spec.rb
|
126
|
+
- spec/spec_helper.rb
|