celluloid-io-pg-listener 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +21 -3
- data/bin/supervisor +25 -0
- data/lib/celluloid-io-pg-listener.rb +5 -4
- data/lib/celluloid-io-pg-listener/client.rb +0 -1
- data/lib/celluloid-io-pg-listener/examples/double_super_example.rb +8 -3
- data/lib/celluloid-io-pg-listener/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b32bda94c9d7c0caa12e0eb1ffe874e2e71fff0
|
4
|
+
data.tar.gz: b81a26d47347897cb829fd411fc672991d2cfec7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3af82bdda3b7154ddf349813da7bffb2a355aebe42cb22f05c57404db242c6557c13e177b05e30337bae2bc459d2eb970aecf82be3bd18476f0ffcb8e87f5700
|
7
|
+
data.tar.gz: ea6c3423da0866304ad84cba117f31ff82a1d4aa5a7e104bb9fbd091f738ad8b5ff418ab483a5eff58a7b76de718981d23a650172b35cb3fd50e06504574f8c3
|
data/README.md
CHANGED
@@ -45,24 +45,42 @@ Find a data base that exists that you want to run notifications through. Won't
|
|
45
45
|
so doesn't matter which one you pick. Then pick an arbitrary name for the channel. Only requirement is that the server
|
46
46
|
and the client use the same database name and channel name or they won't be communicating.
|
47
47
|
|
48
|
-
In an irb session
|
48
|
+
In an irb session taking care to:
|
49
49
|
- replace the database names with your own
|
50
50
|
- replace the channel name, if you want, they are arbitrary, and don't need to be "created" in the DB.
|
51
51
|
|
52
|
+
First load the examples (they are not loaded by default):
|
52
53
|
```ruby
|
53
54
|
>> require "celluloid-io-pg-listener"
|
54
|
-
|
55
55
|
=> true
|
56
|
+
>> require "celluloid-io-pg-listener/examples/client"
|
57
|
+
=> true
|
58
|
+
>> require "celluloid-io-pg-listener/examples/server"
|
59
|
+
=> true
|
60
|
+
>> require "celluloid-io-pg-listener/examples/listener_client_by_inheritance"
|
61
|
+
=> true
|
62
|
+
>> require "celluloid-io-pg-listener/examples/notify_server_by_inheritance"
|
63
|
+
=> true
|
64
|
+
```
|
56
65
|
|
66
|
+
Then turn on debug mode to see what is happening:
|
67
|
+
```
|
57
68
|
>> $CELLULOID_DEBUG=true
|
58
69
|
=> true
|
70
|
+
```
|
59
71
|
|
72
|
+
Then create a server:
|
73
|
+
```
|
60
74
|
>> server = CelluloidIOPGListener::Examples::Server.new(dbname: "celluloid_io_pg_listener_test", channel: "users_insert")
|
61
75
|
|
62
76
|
D, [2015-10-14T12:59:31.840206 #23209] DEBUG -- : Server will send notifications to celluloid_io_pg_listener_test:users_insert
|
63
77
|
|
64
78
|
=> #<Celluloid::Proxy::Cell(CelluloidIOPGListener::Examples::Server:0x3ff71a6f6db8) @client_extracted_signature=#<CelluloidIOPGListener::Initialization::ClientExtractedSignature:0x007fee34dec310 @channel="users_insert", @conninfo_hash={:dbname=>"celluloid_io_pg_listener_test"}, @super_signature=[]>>
|
65
79
|
|
80
|
+
```
|
81
|
+
|
82
|
+
Then start the server sending notifications. There is no client listening to the notifications yet, so nothing will hear them:
|
83
|
+
```
|
66
84
|
>> server.start
|
67
85
|
=> #<Celluloid::Proxy::Async(CelluloidIOPGListener::Examples::Server)>
|
68
86
|
|
@@ -87,7 +105,7 @@ I, [2015-10-14T12:59:49.127509 #23223] INFO -- : Received notification: ["users
|
|
87
105
|
|
88
106
|
Simply exit the sessions to end the test.
|
89
107
|
|
90
|
-
Or keep the client running, and only exit the server and do a real test.
|
108
|
+
Or keep the client running, and only exit the server and do a real test with real DB triggers.
|
91
109
|
|
92
110
|
If you have downloaded the gem source, cd to the gem's directory, and run `bin/setup` to create the test database.
|
93
111
|
|
data/bin/supervisor
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# Run the supervisor from a command prompt like this:
|
3
|
+
#
|
4
|
+
# bin/supervisor &
|
5
|
+
#
|
6
|
+
require "bundler/setup"
|
7
|
+
require "celluloid/current"
|
8
|
+
require "celluloid/supervision"
|
9
|
+
require "celluloid-io-pg-listener"
|
10
|
+
|
11
|
+
module CelluloidIOPGListener
|
12
|
+
class InsertClient
|
13
|
+
include CelluloidIOPGListener::Client
|
14
|
+
def insert_callback(channel, payload)
|
15
|
+
# <-- within the unlisten_wrapper's block if :insert_callback is the callback_method
|
16
|
+
debug "#{self.class} channel is #{channel}"
|
17
|
+
debug "#{self.class} payload is #{payload}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
# TODO: Update DB Connection to default to Heroku DB Connection URL, with the salesforce schema, then fallback to celluloid-io-pg-listener_test
|
22
|
+
class ListeningGroup < Celluloid::Supervision::Container
|
23
|
+
supervise type: CelluloidIOPGListener::InsertClient, as: :insert_client, args: [{dbname: "celluloid_io_pg_listener_test", channel: "users_insert", callback_method: :insert_callback}]
|
24
|
+
end
|
25
|
+
ListeningGroup.run
|
@@ -10,7 +10,8 @@ require "celluloid-io-pg-listener/initialization/client_extracted_signature"
|
|
10
10
|
require "celluloid-io-pg-listener/initialization/argument_extraction"
|
11
11
|
require "celluloid-io-pg-listener/initialization/async_listener"
|
12
12
|
require "celluloid-io-pg-listener/client"
|
13
|
-
|
14
|
-
require "celluloid-io-pg-listener/examples/
|
15
|
-
require "celluloid-io-pg-listener/examples/
|
16
|
-
require "celluloid-io-pg-listener/examples/
|
13
|
+
# Require manually, if you want to try them out.
|
14
|
+
# require "celluloid-io-pg-listener/examples/client"
|
15
|
+
# require "celluloid-io-pg-listener/examples/server"
|
16
|
+
# require "celluloid-io-pg-listener/examples/listener_client_by_inheritance"
|
17
|
+
# require "celluloid-io-pg-listener/examples/notify_server_by_inheritance"
|
@@ -5,7 +5,6 @@ module CelluloidIOPGListener
|
|
5
5
|
class InvalidClient < StandardError; end
|
6
6
|
|
7
7
|
def self.included(base)
|
8
|
-
base.send(:include, Celluloid)
|
9
8
|
base.send(:include, Celluloid::IO)
|
10
9
|
base.send(:include, Celluloid::Internals::Logger)
|
11
10
|
# order of prepended modules is critical if they are enhancing
|
@@ -34,12 +34,17 @@ end
|
|
34
34
|
|
35
35
|
# >> a = HappyMonkey.new(callback_method: "eat_thing")
|
36
36
|
# LOL Nothing happened.
|
37
|
-
# => #<HappyMonkey:
|
37
|
+
# => #<HappyMonkey:0x007f901b877528>
|
38
|
+
#
|
38
39
|
# >> a.eat_thing
|
39
|
-
#
|
40
|
+
# Dreaming about banana
|
40
41
|
# => nil
|
42
|
+
#
|
41
43
|
# >> b = SillyMonkey.new(callback_method: "eat_thing")
|
42
44
|
# LOL Nothing happened.
|
43
|
-
#
|
45
|
+
# => #<SillyMonkey:0x007f90199199b0>
|
46
|
+
#
|
44
47
|
# >> b.eat_thing
|
45
48
|
# RuntimeError: I ate a banana
|
49
|
+
# from (irb):22:in `eat_thing'
|
50
|
+
# from (irb):6:in `block in initialize'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: celluloid-io-pg-listener
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: celluloid-io
|
@@ -184,6 +184,7 @@ files:
|
|
184
184
|
- bin/console
|
185
185
|
- bin/setup
|
186
186
|
- bin/setup.sql
|
187
|
+
- bin/supervisor
|
187
188
|
- celluloid-io-pg-listener.gemspec
|
188
189
|
- gemfiles/rails_3.2.22.gemfile
|
189
190
|
- gemfiles/rails_3.2.22.gemfile.lock
|