momentarily 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.textile +12 -2
- data/lib/momentarily.rb +6 -1
- data/lib/momentarily/version.rb +1 -1
- metadata +71 -89
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a05d24a13b45062b953a411b45b527499a061327
|
4
|
+
data.tar.gz: 685a43ebfb9f9c80e5bca462d6b2cd95dbd70a85
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3a7d155f4d14dc2225ff2ad01736f55a2aeb89b6cdafa2f3e83acb1766d1cd501cff88a2889026ca428e2099efe37e5b41885c4b210f68ff1af52700a269311c
|
7
|
+
data.tar.gz: 3939de0a9b56f71c241c5755e61987af4df70f4740e29ea5295dc55dbcbaafbb310ae04ec82532d2a8c2b6d91b2cf44df3c654822e5dd1955d7b995f13b6c627
|
data/README.textile
CHANGED
@@ -8,16 +8,23 @@ Momentarily is a wrapper around EventMachine with Rails considerations baked in.
|
|
8
8
|
|
9
9
|
To use Momentarily, first add it to your Gemfile:
|
10
10
|
|
11
|
-
|
11
|
+
<pre><code>
|
12
|
+
gem 'momentarily'
|
13
|
+
</code></pre>
|
12
14
|
|
13
15
|
You'll then need to start the reactor. Create a *config/initializers/momentarily.rb* file like this:
|
14
16
|
|
15
|
-
|
17
|
+
<pre><code>
|
18
|
+
Momentarily.start
|
19
|
+
</code></pre>
|
16
20
|
|
17
21
|
That's it! Once complete, *Momentarily.reactor_running?* should be true.
|
18
22
|
|
23
|
+
Note that momentarily will not defer tasks if Rails.env.test? is true.
|
24
|
+
|
19
25
|
Momentarily provides the very useful "later" command. Calling .later will spawn a thread to complete the tasks you provide, allowing your Rails requests to complete and return to users. For example:
|
20
26
|
|
27
|
+
<pre><code>
|
21
28
|
def my_rails_action
|
22
29
|
# do something that has to be done inline
|
23
30
|
Momentarily.later( Proc.new{
|
@@ -28,6 +35,7 @@ def my_rails_action
|
|
28
35
|
})
|
29
36
|
render
|
30
37
|
end
|
38
|
+
</code></pre>
|
31
39
|
|
32
40
|
This will allow your request to complete without waiting for your activities to complete. Note that you are responsible for ensuring that your provided Proc is thread safe.
|
33
41
|
|
@@ -40,6 +48,7 @@ Momentarily.later does the following:
|
|
40
48
|
|
41
49
|
For consistency, Momentarily also provide interfaces *EventMachine.next_tick* and *EventMachine.defer* as *Momentarily.next_tick* and *Momentarily.defer*. Use next_tick to schedule non-blocking IO operations, like AMQP calls or Pusher notifications. *Momentarily.defer* operates similarly to *Momentarily.later*, except *Momentarily.later* checks out an ActiveRecord connection, manages timeouts and handles exceptions for better safety in a Rails environment. We use AMQP also, so our momentarily.rb initializer looks like this:
|
42
50
|
|
51
|
+
<pre><code>
|
43
52
|
require 'amqp'
|
44
53
|
|
45
54
|
Momentarily.start
|
@@ -47,6 +56,7 @@ Momentarily.start
|
|
47
56
|
Momentarily.next_tick( Proc.new {
|
48
57
|
AMQP.channel ||= AMQP::Channel.new(AMQP.connect(:host=> Q_SERVER, :user=> Q_USER, :pass => Q_PASS, :vhost => Q_VHOST ))
|
49
58
|
} )
|
59
|
+
</code></pre>
|
50
60
|
|
51
61
|
Momentarily bridges the gap between using non-blocking IO for asynch operations (like EventMachine) and industrial strength queueing (like RabbitMQ and AMQP) to offload work for later execution. Both have their places, but it's not always feasible to use only non-blocking IO, and it's often not worth the trouble to create messages and a consumer just to shave 500ms off a web request. Our goal is to make it simple to defer even small tasks and ensure a snappy end user experience.
|
52
62
|
|
data/lib/momentarily.rb
CHANGED
@@ -50,7 +50,12 @@ module Momentarily
|
|
50
50
|
end
|
51
51
|
|
52
52
|
def Momentarily.later(work = nil, callback = nil, &block)
|
53
|
-
|
53
|
+
if Rails.env.test?
|
54
|
+
(work || block).call
|
55
|
+
callback.call unless callback.blank?
|
56
|
+
else
|
57
|
+
EM.defer( self.railsify(( work || block )), self.railsify(callback) )
|
58
|
+
end
|
54
59
|
end
|
55
60
|
|
56
61
|
def Momentarily.next_tick(work = nil, &block)
|
data/lib/momentarily/version.rb
CHANGED
metadata
CHANGED
@@ -1,124 +1,106 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: momentarily
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.4
|
11
5
|
platform: ruby
|
12
|
-
authors:
|
6
|
+
authors:
|
13
7
|
- Joshua Siler
|
14
8
|
autorequire:
|
15
9
|
bindir: bin
|
16
10
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
- !ruby/object:Gem::Dependency
|
11
|
+
date: 2016-07-21 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
21
14
|
name: thin
|
22
|
-
|
23
|
-
|
24
|
-
none: false
|
25
|
-
requirements:
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
26
17
|
- - ">="
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
segments:
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
32
20
|
type: :development
|
33
|
-
version_requirements: *id001
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
name: eventmachine
|
36
21
|
prerelease: false
|
37
|
-
|
38
|
-
|
39
|
-
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: eventmachine
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
40
31
|
- - ">="
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
segments:
|
44
|
-
- 0
|
45
|
-
version: "0"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
46
34
|
type: :runtime
|
47
|
-
version_requirements: *id002
|
48
|
-
- !ruby/object:Gem::Dependency
|
49
|
-
name: activerecord
|
50
35
|
prerelease: false
|
51
|
-
|
52
|
-
|
53
|
-
|
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: activerecord
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
54
45
|
- - ">="
|
55
|
-
- !ruby/object:Gem::Version
|
56
|
-
|
57
|
-
segments:
|
58
|
-
- 0
|
59
|
-
version: "0"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
60
48
|
type: :runtime
|
61
|
-
version_requirements: *id003
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: activesupport
|
64
49
|
prerelease: false
|
65
|
-
|
66
|
-
|
67
|
-
|
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: activesupport
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
68
59
|
- - ">="
|
69
|
-
- !ruby/object:Gem::Version
|
70
|
-
|
71
|
-
segments:
|
72
|
-
- 0
|
73
|
-
version: "0"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
74
62
|
type: :runtime
|
75
|
-
|
76
|
-
|
77
|
-
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A rails gem that allows you to briefly defer execution of tasks and return
|
70
|
+
from requests faster.
|
71
|
+
email:
|
78
72
|
- joshua.siler@gmail.com
|
79
73
|
executables: []
|
80
|
-
|
81
74
|
extensions: []
|
82
|
-
|
83
75
|
extra_rdoc_files: []
|
84
|
-
|
85
|
-
|
76
|
+
files:
|
77
|
+
- README.textile
|
86
78
|
- lib/momentarily.rb
|
87
79
|
- lib/momentarily/version.rb
|
88
|
-
- README.textile
|
89
80
|
- test/test_momentarily.rb
|
90
|
-
homepage:
|
81
|
+
homepage: ''
|
91
82
|
licenses: []
|
92
|
-
|
83
|
+
metadata: {}
|
93
84
|
post_install_message:
|
94
85
|
rdoc_options: []
|
95
|
-
|
96
|
-
require_paths:
|
86
|
+
require_paths:
|
97
87
|
- lib
|
98
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
99
|
-
|
100
|
-
requirements:
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
101
90
|
- - ">="
|
102
|
-
- !ruby/object:Gem::Version
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
version: "0"
|
107
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
108
|
-
none: false
|
109
|
-
requirements:
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
110
95
|
- - ">="
|
111
|
-
- !ruby/object:Gem::Version
|
112
|
-
|
113
|
-
segments:
|
114
|
-
- 0
|
115
|
-
version: "0"
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
116
98
|
requirements: []
|
117
|
-
|
118
99
|
rubyforge_project: momentarily
|
119
|
-
rubygems_version:
|
100
|
+
rubygems_version: 2.4.8
|
120
101
|
signing_key:
|
121
|
-
specification_version:
|
122
|
-
summary: A rails gem that allows you to briefly defer execution of tasks and return
|
123
|
-
|
102
|
+
specification_version: 4
|
103
|
+
summary: A rails gem that allows you to briefly defer execution of tasks and return
|
104
|
+
from requests faster.
|
105
|
+
test_files:
|
124
106
|
- test/test_momentarily.rb
|