momentarily 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/lib/momentarily.rb +47 -0
- data/lib/momentarily/version.rb +3 -0
- data/momentarily.gemspec +24 -0
- metadata +71 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/momentarily.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "momentarily/version"
|
2
|
+
require "eventmachine"
|
3
|
+
require 'amqp'
|
4
|
+
|
5
|
+
module Momentarily
|
6
|
+
|
7
|
+
class MomentarilyEM
|
8
|
+
# this pattern is described here http://rdoc.info/github/ruby-amqp/amqp/master/file/docs/ConnectingToTheBroker.textile#In_Web_applications__Ruby_on_Rails__Sinatra__Merb__Rack_
|
9
|
+
# and here: http://railstips.org/blog/archives/2011/05/04/eventmachine-and-passenger/
|
10
|
+
def initialize()
|
11
|
+
self.start()
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.start
|
15
|
+
if defined?(PhusionPassenger)
|
16
|
+
PhusionPassenger.on_event(:starting_worker_process) do |forked|
|
17
|
+
# for passenger, we need to avoid orphaned threads
|
18
|
+
if forked && EM.reactor_running?
|
19
|
+
EM.stop
|
20
|
+
end
|
21
|
+
Thread.new {
|
22
|
+
EM.run do
|
23
|
+
AMQP.channel ||= AMQP::Channel.new(AMQP.connect(:host=> Q_SERVER, :user=> Q_USER, :pass => Q_PASS, :vhost => Q_VHOST ))
|
24
|
+
end
|
25
|
+
}
|
26
|
+
die_gracefully_on_signal
|
27
|
+
end
|
28
|
+
else
|
29
|
+
# faciliates debugging
|
30
|
+
Thread.abort_on_exception = true
|
31
|
+
# just spawn a thread and start it up
|
32
|
+
Thread.new {
|
33
|
+
EM.run do
|
34
|
+
AMQP.channel ||= AMQP::Channel.new(AMQP.connect(:host=> Q_SERVER, :user=> Q_USER, :pass => Q_PASS, :vhost => Q_VHOST ))
|
35
|
+
end
|
36
|
+
} unless defined?(Thin)
|
37
|
+
# Thin is built on EventMachine, doesn't need this thread
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
def self.die_gracefully_on_signal
|
42
|
+
Signal.trap("INT") { EM.stop }
|
43
|
+
Signal.trap("TERM") { EM.stop }
|
44
|
+
end
|
45
|
+
end # MomentarilyEM
|
46
|
+
|
47
|
+
end # Momentarily
|
data/momentarily.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "momentarily/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "momentarily"
|
7
|
+
s.version = Momentarily::VERSION
|
8
|
+
s.authors = ["Joshua Siler"]
|
9
|
+
s.email = ["joshua.siler@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{A rails gem that allows you to briefly defer execution of tasks and return from requests faster.}
|
12
|
+
s.description = %q{A rails gem that allows you to briefly defer execution of tasks and return from requests faster.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "momentarily"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: momentarily
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joshua Siler
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2012-01-15 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: A rails gem that allows you to briefly defer execution of tasks and return from requests faster.
|
22
|
+
email:
|
23
|
+
- joshua.siler@gmail.com
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
extensions: []
|
27
|
+
|
28
|
+
extra_rdoc_files: []
|
29
|
+
|
30
|
+
files:
|
31
|
+
- .gitignore
|
32
|
+
- Gemfile
|
33
|
+
- Rakefile
|
34
|
+
- lib/momentarily.rb
|
35
|
+
- lib/momentarily/version.rb
|
36
|
+
- momentarily.gemspec
|
37
|
+
homepage: ""
|
38
|
+
licenses: []
|
39
|
+
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
|
43
|
+
require_paths:
|
44
|
+
- lib
|
45
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
46
|
+
none: false
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
hash: 3
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
hash: 3
|
60
|
+
segments:
|
61
|
+
- 0
|
62
|
+
version: "0"
|
63
|
+
requirements: []
|
64
|
+
|
65
|
+
rubyforge_project: momentarily
|
66
|
+
rubygems_version: 1.8.10
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: A rails gem that allows you to briefly defer execution of tasks and return from requests faster.
|
70
|
+
test_files: []
|
71
|
+
|