faye-redis-delayed 0.0.1
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 +7 -0
- data/.gitignore +23 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +41 -0
- data/Rakefile +1 -0
- data/faye-redis-delayed.gemspec +24 -0
- data/lib/faye-redis-delayed.rb +1 -0
- data/lib/faye/redis_delayed.rb +56 -0
- metadata +94 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 5bba15ea8458e08d1b6418b19ee79378395f83b5
|
4
|
+
data.tar.gz: ba6ede85751f32d49f88e0580278e2af09a3b75d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 51b998743c677c9ee044f853f100f5169c7d56bbba30e7feaa32be195c5abacf4d243f5e351ac1f79ae9f6af116525ee8b3319dd6f23f470cfa92ce9727cbbf2
|
7
|
+
data.tar.gz: 4fc36f61365e37319acdf24337e084e45e743e2cb7c5e77e325f4c09a27192dbd84cbe9d02c5963d09d048cd6dca74630bb8eb63a178dc7aee3747dfd49798a5
|
data/.gitignore
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
InstalledFiles
|
12
|
+
lib/bundler/man
|
13
|
+
pkg
|
14
|
+
rdoc
|
15
|
+
spec/reports
|
16
|
+
test/tmp
|
17
|
+
test/version_tmp
|
18
|
+
tmp
|
19
|
+
|
20
|
+
# YARD artifacts
|
21
|
+
.yardoc
|
22
|
+
_yardoc
|
23
|
+
doc/
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2013 Monterail
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
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, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Faye::RedisDelayed
|
2
|
+
|
3
|
+
Delayed Redis engine backend for Faye
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'faye-redis-delayed'
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
Pass in the engine and any settings you need when setting up your Faye server.
|
14
|
+
|
15
|
+
```rb
|
16
|
+
require 'faye'
|
17
|
+
require 'faye/redis'
|
18
|
+
|
19
|
+
bayeux = Faye::RackAdapter.new(
|
20
|
+
:mount => '/',
|
21
|
+
:timeout => 25,
|
22
|
+
:engine => {
|
23
|
+
:type => Faye::RedisDelayed,
|
24
|
+
# more options
|
25
|
+
}
|
26
|
+
)
|
27
|
+
```
|
28
|
+
|
29
|
+
Full list of options see [faye-redis](https://github.com/faye/faye-redis-ruby)
|
30
|
+
|
31
|
+
Additional options:
|
32
|
+
|
33
|
+
* <b>`:expire`</b> - expire time in seconds, default 60
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "faye-redis-delayed"
|
7
|
+
spec.version = "0.0.1"
|
8
|
+
spec.authors = ["Dariusz Gertych"]
|
9
|
+
spec.email = ["dariusz.gertych@gmail.com"]
|
10
|
+
spec.description = %q{Delayed Redis engine backend for Faye}
|
11
|
+
spec.summary = %q{Delayed Redis engine backend for Faye}
|
12
|
+
spec.homepage = "https://github.com/monterail/faye-redis-delayed"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files`.split($/)
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'faye-redis', '>= 0.2.0'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require "faye/redis_delayed"
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'faye/redis'
|
2
|
+
|
3
|
+
module Faye
|
4
|
+
class RedisDelayed < Faye::Redis
|
5
|
+
DEFAULT_EXPIRE = 60 # default expiration timeout for awaiting messages
|
6
|
+
|
7
|
+
def subscribe(client_id, channel, &callback)
|
8
|
+
super
|
9
|
+
publish_awaiting_messages(channel)
|
10
|
+
end
|
11
|
+
|
12
|
+
def publish_awaiting_messages(channel)
|
13
|
+
# fetch awaiting messages from redis and publish them
|
14
|
+
@redis.lpop(@ns + "/channels#{channel}/awaiting_messages") do |json_message|
|
15
|
+
if json_message
|
16
|
+
message = Yajl::Parser.parse(json_message)
|
17
|
+
publish(message, [message["channel"]], json_message)
|
18
|
+
publish_awaiting_messages(channel)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def publish(message, channels, json_message = nil)
|
24
|
+
init
|
25
|
+
@server.debug 'Publishing message ?', message
|
26
|
+
|
27
|
+
json_message ||= MultiJson.dump(message)
|
28
|
+
channels = Channel.expand(message['channel'])
|
29
|
+
keys = channels.map { |c| @ns + "/channels#{c}" }
|
30
|
+
|
31
|
+
@redis.sunion(*keys) do |clients|
|
32
|
+
if clients.empty?
|
33
|
+
key = @ns + "/channels#{message["channel"]}/awaiting_messages"
|
34
|
+
# store message in redis
|
35
|
+
@redis.rpush(key, json_message)
|
36
|
+
# Set expiration time to one minute
|
37
|
+
@redis.expire(key, @options[:expire] || DEFAULT_EXPIRE)
|
38
|
+
else
|
39
|
+
clients.each do |client_id|
|
40
|
+
queue = @ns + "/clients/#{client_id}/messages"
|
41
|
+
|
42
|
+
@server.debug 'Queueing for client ?: ?', client_id, message
|
43
|
+
@redis.rpush(queue, json_message)
|
44
|
+
@redis.publish(@message_channel, client_id)
|
45
|
+
|
46
|
+
client_exists(client_id) do |exists|
|
47
|
+
@redis.del(queue) unless exists
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
@server.trigger(:publish, message['clientId'], message['channel'], message['data'])
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
metadata
ADDED
@@ -0,0 +1,94 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faye-redis-delayed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Dariusz Gertych
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-10-30 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faye-redis
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Delayed Redis engine backend for Faye
|
56
|
+
email:
|
57
|
+
- dariusz.gertych@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- .gitignore
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- faye-redis-delayed.gemspec
|
68
|
+
- lib/faye-redis-delayed.rb
|
69
|
+
- lib/faye/redis_delayed.rb
|
70
|
+
homepage: https://github.com/monterail/faye-redis-delayed
|
71
|
+
licenses:
|
72
|
+
- MIT
|
73
|
+
metadata: {}
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
requirements: []
|
89
|
+
rubyforge_project:
|
90
|
+
rubygems_version: 2.0.3
|
91
|
+
signing_key:
|
92
|
+
specification_version: 4
|
93
|
+
summary: Delayed Redis engine backend for Faye
|
94
|
+
test_files: []
|