celluloid-io-pg-listener 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 +11 -0
- data/.rspec +2 -0
- data/.travis.yml +8 -0
- data/Appraisals +10 -0
- data/CODE_OF_CONDUCT.md +13 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +148 -0
- data/Rakefile +8 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/celluloid-io-pg-listener.gemspec +29 -0
- data/gemfiles/rails_3.2.22.gemfile +8 -0
- data/gemfiles/rails_3.2.22.gemfile.lock +154 -0
- data/gemfiles/rails_4.2.4.gemfile +8 -0
- data/gemfiles/rails_4.2.4.gemfile.lock +167 -0
- data/lib/celluloid-io-pg-listener.rb +11 -0
- data/lib/celluloid-io-pg-listener/client.rb +76 -0
- data/lib/celluloid-io-pg-listener/listener.rb +21 -0
- data/lib/celluloid-io-pg-listener/server.rb +38 -0
- data/lib/celluloid-io-pg-listener/version.rb +3 -0
- metadata +165 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6688ff5db3f6b68ae8cb6c3d30d1c7324255285d
|
4
|
+
data.tar.gz: 1aa1956925611e9bbdda6a966dca67d872a0ebf9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7d6313905452f4c1ba7521ea991688d53bca029de7bbec76df0ce16e791cc66d5e4bb8285a44f27e9855a2d1f84ffde0815f4cc9088ab349fd4a00b1848ac762
|
7
|
+
data.tar.gz: 67c96d9e54a750629e46f7cd996ded67a034e056ee537b72337acc1d0f319a05ce11d59db7392ad86397c9c893f39c58132f3f5f84681d5c5dcd9dbde1af015c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Appraisals
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
+
|
5
|
+
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
|
6
|
+
|
7
|
+
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
+
|
9
|
+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
+
|
11
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
+
|
13
|
+
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Peter Boling
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
# celluloid-io-pg-listener
|
2
|
+
|
3
|
+
Simple way to NOTIFY and LISTEN to channels in PostgreSQL
|
4
|
+
|
5
|
+
Inspired by https://gist.github.com/tpitale/3915671
|
6
|
+
|
7
|
+
| Project | Celluloid IO PG Listener |
|
8
|
+
|------------------------ | ----------------- |
|
9
|
+
| gem name | celluloid-io-pg-listener |
|
10
|
+
| license | MIT |
|
11
|
+
| moldiness | [![Maintainer Status](http://stillmaintained.com/pboling/celluloid-io-pg-listener.png)](http://stillmaintained.com/pboling/celluloid-io-pg-listener) |
|
12
|
+
| version | [![Gem Version](https://badge.fury.io/rb/celluloid-io-pg-listener.png)](http://badge.fury.io/rb/celluloid-io-pg-listener) |
|
13
|
+
| dependencies | [![Dependency Status](https://gemnasium.com/pboling/celluloid-io-pg-listener.png)](https://gemnasium.com/pboling/celluloid-io-pg-listener) |
|
14
|
+
| code quality | [![Code Climate](https://codeclimate.com/github/pboling/celluloid-io-pg-listener.png)](https://codeclimate.com/github/pboling/celluloid-io-pg-listener) |
|
15
|
+
| inline documenation | [![Inline docs](http://inch-ci.org/github/pboling/celluloid-io-pg-listener.png)](http://inch-ci.org/github/pboling/celluloid-io-pg-listener) |
|
16
|
+
| continuous integration | [![Build Status](https://secure.travis-ci.org/pboling/celluloid-io-pg-listener.png?branch=master)](https://travis-ci.org/pboling/celluloid-io-pg-listener) |
|
17
|
+
| test coverage | [![Coverage Status](https://coveralls.io/repos/pboling/celluloid-io-pg-listener/badge.png)](https://coveralls.io/r/pboling/celluloid-io-pg-listener) |
|
18
|
+
| homepage | [https://github.com/pboling/celluloid-io-pg-listener][homepage] |
|
19
|
+
| documentation | [http://rdoc.info/github/pboling/celluloid-io-pg-listener/frames][documentation] |
|
20
|
+
| author | [Peter Boling](https://coderbits.com/pboling) |
|
21
|
+
| Spread ~♡ⓛⓞⓥⓔ♡~ | [![Endorse Me](https://api.coderwall.com/pboling/endorsecount.png)](http://coderwall.com/pboling) |
|
22
|
+
|
23
|
+
|
24
|
+
## Installation
|
25
|
+
|
26
|
+
Add this line to your application's Gemfile:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
gem 'celluloid-io-pg-listener'
|
30
|
+
```
|
31
|
+
|
32
|
+
And then execute:
|
33
|
+
|
34
|
+
$ bundle
|
35
|
+
|
36
|
+
Or install it yourself as:
|
37
|
+
|
38
|
+
$ gem install celluloid-io-pg-listener
|
39
|
+
|
40
|
+
## Usage
|
41
|
+
|
42
|
+
Find a data base that exists that you want to run notifications through. Won't affect anything else in the database,
|
43
|
+
so doesn't matter which one you pick. Then pick an arbitrary name for the channel. Only requirement is that the server
|
44
|
+
and the client use the same database name and channel name or they won't be communicating.
|
45
|
+
|
46
|
+
In an irb session
|
47
|
+
|
48
|
+
```ruby
|
49
|
+
>> require "celluloid-io-pg-listener"
|
50
|
+
|
51
|
+
=> true
|
52
|
+
|
53
|
+
>> CelluloidIOPGListener::Server.new(dbname: "test_database", channel: "test_channel" )
|
54
|
+
|
55
|
+
I, [2015-10-06T12:38:43.728686 #5880] INFO -- : Server will send notifications to archer_test:test
|
56
|
+
|
57
|
+
=> #<Celluloid::Proxy::Cell(CelluloidIOPGListener::Server:0x3ff732194f24) @dbname="test_database" @channel="test_channel" @sleep_interval=0.1 @run_interval=1>
|
58
|
+
|
59
|
+
I, [2015-10-06T12:38:44.105265 #5880] INFO -- : Notified test
|
60
|
+
|
61
|
+
>> CelluloidIOPGListener::Listener.new(dbname: "test_database", channel: "test_channel" )
|
62
|
+
|
63
|
+
=> #<Celluloid::Proxy::Cell(CelluloidIOPGListener::Listener:0x3fd6ace33cb8) @dbname="test_database" @listening=true @pg_connection=#<PG::Connection:0x007fad59c5f978> @actions={"test_channel"=>:do_something}>
|
64
|
+
|
65
|
+
I, [2015-10-06T12:40:38.110541 #5952] INFO -- : Client will for notifications on test_database:test_channel
|
66
|
+
I, [2015-10-06T12:40:38.110822 #5952] INFO -- : Starting Listening
|
67
|
+
I, [2015-10-06T12:40:50.117444 #5952] INFO -- : Received notification: ["test", 5968, "1444160450"]
|
68
|
+
I, [2015-10-06T12:40:50.117518 #5952] INFO -- : Doing Something with Payload: 1444160450 on test
|
69
|
+
I, [2015-10-06T12:40:50.117541 #5952] INFO -- : 1444160450
|
70
|
+
I, [2015-10-06T12:40:51.107977 #5952] INFO -- : Received notification: ["test", 5968, "1444160451"]
|
71
|
+
I, [2015-10-06T12:40:51.108071 #5952] INFO -- : Doing Something with Payload: 1444160451 on test
|
72
|
+
I, [2015-10-06T12:40:51.108104 #5952] INFO -- : 1444160451
|
73
|
+
I, [2015-10-06T12:40:52.112797 #5952] INFO -- : Received notification: ["test", 5968, "1444160452"]
|
74
|
+
I, [2015-10-06T12:40:52.112881 #5952] INFO -- : Doing Something with Payload: 1444160452 on test
|
75
|
+
I, [2015-10-06T12:40:52.112911 #5952] INFO -- : 1444160452
|
76
|
+
```
|
77
|
+
|
78
|
+
The Listener class included is just a proof of concept. It shows you how to use the Client module to make your own listener class that does what you need done.
|
79
|
+
|
80
|
+
```ruby
|
81
|
+
module CelluloidIOPGListener
|
82
|
+
# An example Client class
|
83
|
+
class Listener
|
84
|
+
|
85
|
+
include CelluloidIOPGListener::Client
|
86
|
+
|
87
|
+
def initialize(dbname:, channel:)
|
88
|
+
info "Client will for notifications on #{dbname}:#{channel}"
|
89
|
+
@dbname = dbname
|
90
|
+
async.start_listening
|
91
|
+
async.listen(channel, :do_something)
|
92
|
+
end
|
93
|
+
|
94
|
+
def do_something(channel, payload)
|
95
|
+
unlisten_wrapper(channel, payload) do
|
96
|
+
info payload
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
```
|
103
|
+
|
104
|
+
## Development
|
105
|
+
|
106
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
107
|
+
|
108
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
109
|
+
|
110
|
+
## Contributing
|
111
|
+
|
112
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/celluloid-io-pg-listener. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
113
|
+
|
114
|
+
1. Fork it
|
115
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
116
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
117
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
118
|
+
5. Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
119
|
+
6. Create new Pull Request
|
120
|
+
|
121
|
+
## Versioning
|
122
|
+
|
123
|
+
This library aims to adhere to [Semantic Versioning 2.0.0][semver].
|
124
|
+
Violations of this scheme should be reported as bugs. Specifically,
|
125
|
+
if a minor or patch version is released that breaks backward
|
126
|
+
compatibility, a new version should be immediately released that
|
127
|
+
restores compatibility. Breaking changes to the public API will
|
128
|
+
only be introduced with new major versions.
|
129
|
+
|
130
|
+
As a result of this policy, you can (and should) specify a
|
131
|
+
dependency on this gem using the [Pessimistic Version Constraint][pvc] with two digits of precision.
|
132
|
+
|
133
|
+
For example:
|
134
|
+
|
135
|
+
```ruby
|
136
|
+
spec.add_dependency 'celluloid-io-pg-listener', '~> 0.1'
|
137
|
+
```
|
138
|
+
|
139
|
+
|
140
|
+
## License
|
141
|
+
|
142
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
143
|
+
|
144
|
+
[semver]: http://semver.org/
|
145
|
+
[pvc]: http://docs.rubygems.org/read/chapter/16#page74
|
146
|
+
[railsbling]: http://www.railsbling.com
|
147
|
+
[documentation]: http://rdoc.info/github/pboling/celluloid-io-pg-listener/frames
|
148
|
+
[homepage]: https://github.com/pboling/celluloid-io-pg-listener
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "celluloid-io-pg-listener"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "celluloid-io-pg-listener/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "celluloid-io-pg-listener"
|
8
|
+
spec.version = CelluloidIOPGListener::VERSION
|
9
|
+
spec.authors = ["Peter Boling"]
|
10
|
+
spec.email = ["peter.boling@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Asynchronously LISTEN for Postgresql NOTIFY messages with payloads and Do Something}
|
13
|
+
spec.description = %q{Asynchronously LISTEN for Postgresql NOTIFY messages with payloads and Do Something}
|
14
|
+
spec.homepage = "https://github.com/pboling/celluloid-io-pg-listener"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec)/}) }
|
18
|
+
spec.bindir = "exe"
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "celluloid-io", ">= 0.17.2"
|
23
|
+
spec.add_dependency "pg", ">= 0.18.3"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec"
|
27
|
+
spec.add_development_dependency "rspec-rails"
|
28
|
+
spec.add_development_dependency "appraisal"
|
29
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
celluloid-io-pg-listener (0.1.0)
|
5
|
+
celluloid-io (>= 0.17.2)
|
6
|
+
pg (>= 0.18.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (3.2.22)
|
12
|
+
actionpack (= 3.2.22)
|
13
|
+
mail (~> 2.5.4)
|
14
|
+
actionpack (3.2.22)
|
15
|
+
activemodel (= 3.2.22)
|
16
|
+
activesupport (= 3.2.22)
|
17
|
+
builder (~> 3.0.0)
|
18
|
+
erubis (~> 2.7.0)
|
19
|
+
journey (~> 1.0.4)
|
20
|
+
rack (~> 1.4.5)
|
21
|
+
rack-cache (~> 1.2)
|
22
|
+
rack-test (~> 0.6.1)
|
23
|
+
sprockets (~> 2.2.1)
|
24
|
+
activemodel (3.2.22)
|
25
|
+
activesupport (= 3.2.22)
|
26
|
+
builder (~> 3.0.0)
|
27
|
+
activerecord (3.2.22)
|
28
|
+
activemodel (= 3.2.22)
|
29
|
+
activesupport (= 3.2.22)
|
30
|
+
arel (~> 3.0.2)
|
31
|
+
tzinfo (~> 0.3.29)
|
32
|
+
activeresource (3.2.22)
|
33
|
+
activemodel (= 3.2.22)
|
34
|
+
activesupport (= 3.2.22)
|
35
|
+
activesupport (3.2.22)
|
36
|
+
i18n (~> 0.6, >= 0.6.4)
|
37
|
+
multi_json (~> 1.0)
|
38
|
+
appraisal (2.1.0)
|
39
|
+
bundler
|
40
|
+
rake
|
41
|
+
thor (>= 0.14.0)
|
42
|
+
arel (3.0.3)
|
43
|
+
builder (3.0.4)
|
44
|
+
celluloid (0.17.2)
|
45
|
+
celluloid-essentials
|
46
|
+
celluloid-extras
|
47
|
+
celluloid-fsm
|
48
|
+
celluloid-pool
|
49
|
+
celluloid-supervision
|
50
|
+
timers (>= 4.1.1)
|
51
|
+
celluloid-essentials (0.20.5)
|
52
|
+
timers (>= 4.1.1)
|
53
|
+
celluloid-extras (0.20.5)
|
54
|
+
timers (>= 4.1.1)
|
55
|
+
celluloid-fsm (0.20.5)
|
56
|
+
timers (>= 4.1.1)
|
57
|
+
celluloid-io (0.17.2)
|
58
|
+
celluloid (>= 0.17.2)
|
59
|
+
nio4r (>= 1.1)
|
60
|
+
timers (>= 4.1.1)
|
61
|
+
celluloid-pool (0.20.5)
|
62
|
+
timers (>= 4.1.1)
|
63
|
+
celluloid-supervision (0.20.5)
|
64
|
+
timers (>= 4.1.1)
|
65
|
+
diff-lcs (1.2.5)
|
66
|
+
erubis (2.7.0)
|
67
|
+
hike (1.2.3)
|
68
|
+
hitimes (1.2.3)
|
69
|
+
i18n (0.7.0)
|
70
|
+
journey (1.0.4)
|
71
|
+
json (1.8.3)
|
72
|
+
mail (2.5.4)
|
73
|
+
mime-types (~> 1.16)
|
74
|
+
treetop (~> 1.4.8)
|
75
|
+
mime-types (1.25.1)
|
76
|
+
multi_json (1.11.2)
|
77
|
+
nio4r (1.1.1)
|
78
|
+
pg (0.18.3)
|
79
|
+
polyglot (0.3.5)
|
80
|
+
rack (1.4.7)
|
81
|
+
rack-cache (1.2)
|
82
|
+
rack (>= 0.4)
|
83
|
+
rack-ssl (1.3.4)
|
84
|
+
rack
|
85
|
+
rack-test (0.6.3)
|
86
|
+
rack (>= 1.0)
|
87
|
+
rails (3.2.22)
|
88
|
+
actionmailer (= 3.2.22)
|
89
|
+
actionpack (= 3.2.22)
|
90
|
+
activerecord (= 3.2.22)
|
91
|
+
activeresource (= 3.2.22)
|
92
|
+
activesupport (= 3.2.22)
|
93
|
+
bundler (~> 1.0)
|
94
|
+
railties (= 3.2.22)
|
95
|
+
railties (3.2.22)
|
96
|
+
actionpack (= 3.2.22)
|
97
|
+
activesupport (= 3.2.22)
|
98
|
+
rack-ssl (~> 1.3.2)
|
99
|
+
rake (>= 0.8.7)
|
100
|
+
rdoc (~> 3.4)
|
101
|
+
thor (>= 0.14.6, < 2.0)
|
102
|
+
rake (10.4.2)
|
103
|
+
rdoc (3.12.2)
|
104
|
+
json (~> 1.4)
|
105
|
+
rspec (3.3.0)
|
106
|
+
rspec-core (~> 3.3.0)
|
107
|
+
rspec-expectations (~> 3.3.0)
|
108
|
+
rspec-mocks (~> 3.3.0)
|
109
|
+
rspec-core (3.3.2)
|
110
|
+
rspec-support (~> 3.3.0)
|
111
|
+
rspec-expectations (3.3.1)
|
112
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
113
|
+
rspec-support (~> 3.3.0)
|
114
|
+
rspec-mocks (3.3.2)
|
115
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
116
|
+
rspec-support (~> 3.3.0)
|
117
|
+
rspec-rails (3.3.3)
|
118
|
+
actionpack (>= 3.0, < 4.3)
|
119
|
+
activesupport (>= 3.0, < 4.3)
|
120
|
+
railties (>= 3.0, < 4.3)
|
121
|
+
rspec-core (~> 3.3.0)
|
122
|
+
rspec-expectations (~> 3.3.0)
|
123
|
+
rspec-mocks (~> 3.3.0)
|
124
|
+
rspec-support (~> 3.3.0)
|
125
|
+
rspec-support (3.3.0)
|
126
|
+
sprockets (2.2.3)
|
127
|
+
hike (~> 1.2)
|
128
|
+
multi_json (~> 1.0)
|
129
|
+
rack (~> 1.0)
|
130
|
+
tilt (~> 1.1, != 1.3.0)
|
131
|
+
thor (0.19.1)
|
132
|
+
tilt (1.4.1)
|
133
|
+
timers (4.1.1)
|
134
|
+
hitimes
|
135
|
+
treetop (1.4.15)
|
136
|
+
polyglot
|
137
|
+
polyglot (>= 0.3.1)
|
138
|
+
tzinfo (0.3.45)
|
139
|
+
|
140
|
+
PLATFORMS
|
141
|
+
ruby
|
142
|
+
|
143
|
+
DEPENDENCIES
|
144
|
+
appraisal
|
145
|
+
bundler (~> 1.10)
|
146
|
+
celluloid-io-pg-listener!
|
147
|
+
pg
|
148
|
+
rails (~> 3.2.22)
|
149
|
+
rake (~> 10.0)
|
150
|
+
rspec
|
151
|
+
rspec-rails
|
152
|
+
|
153
|
+
BUNDLED WITH
|
154
|
+
1.10.6
|
@@ -0,0 +1,167 @@
|
|
1
|
+
PATH
|
2
|
+
remote: ../
|
3
|
+
specs:
|
4
|
+
celluloid-io-pg-listener (0.1.0)
|
5
|
+
celluloid-io (>= 0.17.2)
|
6
|
+
pg (>= 0.18.3)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
actionmailer (4.2.4)
|
12
|
+
actionpack (= 4.2.4)
|
13
|
+
actionview (= 4.2.4)
|
14
|
+
activejob (= 4.2.4)
|
15
|
+
mail (~> 2.5, >= 2.5.4)
|
16
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
17
|
+
actionpack (4.2.4)
|
18
|
+
actionview (= 4.2.4)
|
19
|
+
activesupport (= 4.2.4)
|
20
|
+
rack (~> 1.6)
|
21
|
+
rack-test (~> 0.6.2)
|
22
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
23
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
24
|
+
actionview (4.2.4)
|
25
|
+
activesupport (= 4.2.4)
|
26
|
+
builder (~> 3.1)
|
27
|
+
erubis (~> 2.7.0)
|
28
|
+
rails-dom-testing (~> 1.0, >= 1.0.5)
|
29
|
+
rails-html-sanitizer (~> 1.0, >= 1.0.2)
|
30
|
+
activejob (4.2.4)
|
31
|
+
activesupport (= 4.2.4)
|
32
|
+
globalid (>= 0.3.0)
|
33
|
+
activemodel (4.2.4)
|
34
|
+
activesupport (= 4.2.4)
|
35
|
+
builder (~> 3.1)
|
36
|
+
activerecord (4.2.4)
|
37
|
+
activemodel (= 4.2.4)
|
38
|
+
activesupport (= 4.2.4)
|
39
|
+
arel (~> 6.0)
|
40
|
+
activesupport (4.2.4)
|
41
|
+
i18n (~> 0.7)
|
42
|
+
json (~> 1.7, >= 1.7.7)
|
43
|
+
minitest (~> 5.1)
|
44
|
+
thread_safe (~> 0.3, >= 0.3.4)
|
45
|
+
tzinfo (~> 1.1)
|
46
|
+
appraisal (2.1.0)
|
47
|
+
bundler
|
48
|
+
rake
|
49
|
+
thor (>= 0.14.0)
|
50
|
+
arel (6.0.3)
|
51
|
+
builder (3.2.2)
|
52
|
+
celluloid (0.17.2)
|
53
|
+
celluloid-essentials
|
54
|
+
celluloid-extras
|
55
|
+
celluloid-fsm
|
56
|
+
celluloid-pool
|
57
|
+
celluloid-supervision
|
58
|
+
timers (>= 4.1.1)
|
59
|
+
celluloid-essentials (0.20.5)
|
60
|
+
timers (>= 4.1.1)
|
61
|
+
celluloid-extras (0.20.5)
|
62
|
+
timers (>= 4.1.1)
|
63
|
+
celluloid-fsm (0.20.5)
|
64
|
+
timers (>= 4.1.1)
|
65
|
+
celluloid-io (0.17.2)
|
66
|
+
celluloid (>= 0.17.2)
|
67
|
+
nio4r (>= 1.1)
|
68
|
+
timers (>= 4.1.1)
|
69
|
+
celluloid-pool (0.20.5)
|
70
|
+
timers (>= 4.1.1)
|
71
|
+
celluloid-supervision (0.20.5)
|
72
|
+
timers (>= 4.1.1)
|
73
|
+
diff-lcs (1.2.5)
|
74
|
+
erubis (2.7.0)
|
75
|
+
globalid (0.3.6)
|
76
|
+
activesupport (>= 4.1.0)
|
77
|
+
hitimes (1.2.3)
|
78
|
+
i18n (0.7.0)
|
79
|
+
json (1.8.3)
|
80
|
+
loofah (2.0.3)
|
81
|
+
nokogiri (>= 1.5.9)
|
82
|
+
mail (2.6.3)
|
83
|
+
mime-types (>= 1.16, < 3)
|
84
|
+
mime-types (2.6.2)
|
85
|
+
mini_portile (0.6.2)
|
86
|
+
minitest (5.8.1)
|
87
|
+
nio4r (1.1.1)
|
88
|
+
nokogiri (1.6.6.2)
|
89
|
+
mini_portile (~> 0.6.0)
|
90
|
+
pg (0.18.3)
|
91
|
+
rack (1.6.4)
|
92
|
+
rack-test (0.6.3)
|
93
|
+
rack (>= 1.0)
|
94
|
+
rails (4.2.4)
|
95
|
+
actionmailer (= 4.2.4)
|
96
|
+
actionpack (= 4.2.4)
|
97
|
+
actionview (= 4.2.4)
|
98
|
+
activejob (= 4.2.4)
|
99
|
+
activemodel (= 4.2.4)
|
100
|
+
activerecord (= 4.2.4)
|
101
|
+
activesupport (= 4.2.4)
|
102
|
+
bundler (>= 1.3.0, < 2.0)
|
103
|
+
railties (= 4.2.4)
|
104
|
+
sprockets-rails
|
105
|
+
rails-deprecated_sanitizer (1.0.3)
|
106
|
+
activesupport (>= 4.2.0.alpha)
|
107
|
+
rails-dom-testing (1.0.7)
|
108
|
+
activesupport (>= 4.2.0.beta, < 5.0)
|
109
|
+
nokogiri (~> 1.6.0)
|
110
|
+
rails-deprecated_sanitizer (>= 1.0.1)
|
111
|
+
rails-html-sanitizer (1.0.2)
|
112
|
+
loofah (~> 2.0)
|
113
|
+
railties (4.2.4)
|
114
|
+
actionpack (= 4.2.4)
|
115
|
+
activesupport (= 4.2.4)
|
116
|
+
rake (>= 0.8.7)
|
117
|
+
thor (>= 0.18.1, < 2.0)
|
118
|
+
rake (10.4.2)
|
119
|
+
rspec (3.3.0)
|
120
|
+
rspec-core (~> 3.3.0)
|
121
|
+
rspec-expectations (~> 3.3.0)
|
122
|
+
rspec-mocks (~> 3.3.0)
|
123
|
+
rspec-core (3.3.2)
|
124
|
+
rspec-support (~> 3.3.0)
|
125
|
+
rspec-expectations (3.3.1)
|
126
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
127
|
+
rspec-support (~> 3.3.0)
|
128
|
+
rspec-mocks (3.3.2)
|
129
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
130
|
+
rspec-support (~> 3.3.0)
|
131
|
+
rspec-rails (3.3.3)
|
132
|
+
actionpack (>= 3.0, < 4.3)
|
133
|
+
activesupport (>= 3.0, < 4.3)
|
134
|
+
railties (>= 3.0, < 4.3)
|
135
|
+
rspec-core (~> 3.3.0)
|
136
|
+
rspec-expectations (~> 3.3.0)
|
137
|
+
rspec-mocks (~> 3.3.0)
|
138
|
+
rspec-support (~> 3.3.0)
|
139
|
+
rspec-support (3.3.0)
|
140
|
+
sprockets (3.3.5)
|
141
|
+
rack (> 1, < 3)
|
142
|
+
sprockets-rails (2.3.3)
|
143
|
+
actionpack (>= 3.0)
|
144
|
+
activesupport (>= 3.0)
|
145
|
+
sprockets (>= 2.8, < 4.0)
|
146
|
+
thor (0.19.1)
|
147
|
+
thread_safe (0.3.5)
|
148
|
+
timers (4.1.1)
|
149
|
+
hitimes
|
150
|
+
tzinfo (1.2.2)
|
151
|
+
thread_safe (~> 0.1)
|
152
|
+
|
153
|
+
PLATFORMS
|
154
|
+
ruby
|
155
|
+
|
156
|
+
DEPENDENCIES
|
157
|
+
appraisal
|
158
|
+
bundler (~> 1.10)
|
159
|
+
celluloid-io-pg-listener!
|
160
|
+
pg
|
161
|
+
rails (~> 4.2.4)
|
162
|
+
rake (~> 10.0)
|
163
|
+
rspec
|
164
|
+
rspec-rails
|
165
|
+
|
166
|
+
BUNDLED WITH
|
167
|
+
1.10.6
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "celluloid-io-pg-listener/version"
|
2
|
+
require "celluloid/current" # See https://github.com/celluloid/celluloid/wiki/DEPRECATION-WARNING
|
3
|
+
require "celluloid/io"
|
4
|
+
require "pg"
|
5
|
+
|
6
|
+
# Define the namespace this gem uses
|
7
|
+
module CelluloidIOPGListener; end
|
8
|
+
|
9
|
+
require "celluloid-io-pg-listener/client"
|
10
|
+
require "celluloid-io-pg-listener/server"
|
11
|
+
require "celluloid-io-pg-listener/listener"
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# Client for listening for notifications sent through postgresql.
|
2
|
+
module CelluloidIOPGListener
|
3
|
+
module Client
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.send(:include, Celluloid)
|
7
|
+
base.send(:include, Celluloid::IO)
|
8
|
+
base.send(:include, Celluloid::Internals::Logger)
|
9
|
+
end
|
10
|
+
|
11
|
+
def unlisten_wrapper(channel, payload, &block)
|
12
|
+
info "Doing Something with Payload: #{payload} on #{channel}"
|
13
|
+
instance_eval(&block)
|
14
|
+
rescue => e
|
15
|
+
info "#{self.class} disconnected from #{channel} via #{e.class} #{e.message}"
|
16
|
+
unlisten(channel)
|
17
|
+
terminate
|
18
|
+
end
|
19
|
+
|
20
|
+
def actions
|
21
|
+
@actions ||= {}
|
22
|
+
end
|
23
|
+
|
24
|
+
def pg_connection
|
25
|
+
@pg_connection ||= PG.connect( dbname: @dbname )
|
26
|
+
end
|
27
|
+
|
28
|
+
def notify(channel, value)
|
29
|
+
pg_connection.exec("NOTIFY #{channel}, '#{value}';")
|
30
|
+
end
|
31
|
+
|
32
|
+
def listen(channel, action)
|
33
|
+
actions[channel] = action
|
34
|
+
pg_connection.exec("LISTEN #{channel}")
|
35
|
+
end
|
36
|
+
|
37
|
+
def start_listening
|
38
|
+
info "Starting Listening"
|
39
|
+
|
40
|
+
@listening = true
|
41
|
+
|
42
|
+
wait_for_notify do |channel, pid, payload|
|
43
|
+
info "Received notification: #{[channel, pid, payload].inspect}"
|
44
|
+
send(actions[channel], channel, payload)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def stop_listening
|
49
|
+
@listening = false
|
50
|
+
end
|
51
|
+
|
52
|
+
def wait_for_notify(&block)
|
53
|
+
io = pg_connection.socket_io
|
54
|
+
|
55
|
+
while @listening do
|
56
|
+
Celluloid::IO.wait_readable(io) # blocks execution, but unblocks this actor
|
57
|
+
pg_connection.consume_input # fetch any input on this connection
|
58
|
+
|
59
|
+
while notification = pg_connection.notifies do
|
60
|
+
block.call(*[
|
61
|
+
notification[:relname], # channel
|
62
|
+
notification[:be_pid], # pid
|
63
|
+
notification[:extra] # payload
|
64
|
+
])
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def unlisten(channel)
|
70
|
+
# (@listening ||= {})[channel] = false
|
71
|
+
stop_listening # Not sure if there is a way to stop listening to a single channel without affecting the others.
|
72
|
+
pg_connection.exec("UNLISTEN #{channel}")
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CelluloidIOPGListener
|
2
|
+
# An example Client class
|
3
|
+
class Listener
|
4
|
+
|
5
|
+
include CelluloidIOPGListener::Client
|
6
|
+
|
7
|
+
def initialize(dbname:, channel:)
|
8
|
+
info "Client will for notifications on #{dbname}:#{channel}"
|
9
|
+
@dbname = dbname
|
10
|
+
async.start_listening
|
11
|
+
async.listen(channel, :do_something)
|
12
|
+
end
|
13
|
+
|
14
|
+
def do_something(channel, payload)
|
15
|
+
unlisten_wrapper(channel, payload) do
|
16
|
+
info payload
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# Simple example of a server for sending notifications through postgresql that can be listened for.
|
2
|
+
class CelluloidIOPGListener::Server
|
3
|
+
|
4
|
+
include Celluloid
|
5
|
+
include Celluloid::IO
|
6
|
+
include Celluloid::Internals::Logger
|
7
|
+
|
8
|
+
# Defaults:
|
9
|
+
# 1/10th of a second sleep intervals
|
10
|
+
# 1 second run intervals
|
11
|
+
def initialize(dbname:, channel:, run_interval: 1, sleep_interval: 0.1)
|
12
|
+
info "Server will send notifications to #{dbname}:#{channel}"
|
13
|
+
@dbname = dbname
|
14
|
+
@channel = channel
|
15
|
+
@sleep_interval = sleep_interval
|
16
|
+
@run_interval = run_interval
|
17
|
+
async.run
|
18
|
+
end
|
19
|
+
|
20
|
+
def run
|
21
|
+
now = Time.now.to_f
|
22
|
+
sleep now.ceil - now + @sleep_interval
|
23
|
+
# There is no way to pass anything into the block, which is why this server isn't all that useful.
|
24
|
+
# The client is intended to listen to notifications coming from other sources,
|
25
|
+
# like a PG TRIGGER than sends a notification on INSERT, for example.
|
26
|
+
every(@run_interval) { notify(@channel, Time.now.to_i) }
|
27
|
+
info "Notified #{@channel}"
|
28
|
+
end
|
29
|
+
|
30
|
+
def pg_connection
|
31
|
+
@pg_connection ||= PG.connect( dbname: @dbname )
|
32
|
+
end
|
33
|
+
|
34
|
+
def notify(channel, value)
|
35
|
+
pg_connection.exec("NOTIFY #{channel}, '#{value}';")
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: celluloid-io-pg-listener
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Peter Boling
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: celluloid-io
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.17.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.17.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pg
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.18.3
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.18.3
|
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.10'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.10'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.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
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec-rails
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: appraisal
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Asynchronously LISTEN for Postgresql NOTIFY messages with payloads and
|
112
|
+
Do Something
|
113
|
+
email:
|
114
|
+
- peter.boling@gmail.com
|
115
|
+
executables: []
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Appraisals
|
123
|
+
- CODE_OF_CONDUCT.md
|
124
|
+
- Gemfile
|
125
|
+
- LICENSE.txt
|
126
|
+
- README.md
|
127
|
+
- Rakefile
|
128
|
+
- bin/console
|
129
|
+
- bin/setup
|
130
|
+
- celluloid-io-pg-listener.gemspec
|
131
|
+
- gemfiles/rails_3.2.22.gemfile
|
132
|
+
- gemfiles/rails_3.2.22.gemfile.lock
|
133
|
+
- gemfiles/rails_4.2.4.gemfile
|
134
|
+
- gemfiles/rails_4.2.4.gemfile.lock
|
135
|
+
- lib/celluloid-io-pg-listener.rb
|
136
|
+
- lib/celluloid-io-pg-listener/client.rb
|
137
|
+
- lib/celluloid-io-pg-listener/listener.rb
|
138
|
+
- lib/celluloid-io-pg-listener/server.rb
|
139
|
+
- lib/celluloid-io-pg-listener/version.rb
|
140
|
+
homepage: https://github.com/pboling/celluloid-io-pg-listener
|
141
|
+
licenses:
|
142
|
+
- MIT
|
143
|
+
metadata: {}
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
require_paths:
|
147
|
+
- lib
|
148
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
requirements: []
|
159
|
+
rubyforge_project:
|
160
|
+
rubygems_version: 2.4.8
|
161
|
+
signing_key:
|
162
|
+
specification_version: 4
|
163
|
+
summary: Asynchronously LISTEN for Postgresql NOTIFY messages with payloads and Do
|
164
|
+
Something
|
165
|
+
test_files: []
|