Add couchbase with modifications, formalize broadcaster and make testable and some other stuff

This commit is contained in:
2014-03-06 18:08:39 +01:00
parent 3f117c76b0
commit 0e7a39b819
28 changed files with 456 additions and 35 deletions
+44
View File
@@ -0,0 +1,44 @@
# This is a replacement of the couchbase settings gem. The quality of this gem is not sufficient to
# work with. Since couchbase structures/docstore are using CouchbaseSetting we supply the right settings
# here
module CouchbaseSetting
mattr_accessor :config_type
mattr_accessor :configs
def self.server
config :server, default: '127.0.0.1'
end
def self.bucket
config :bucket, default: 'qwaiter'
end
def self.config(setting, default: nil)
configs[config_type][Rails.env.to_sym][setting] || default
end
end
CouchbaseSetting.configs = {
supplier_counters: {
development: {
bucket: 'qwaiter_development'
},
test:{
bucket: 'qwaiter_development'
},
production: {}
},
queue: {
development: {
bucket: 'qwaiter_development'
},
test:{
bucket: 'qwaiter_development'
},
production: {}
}
}
# only one in use at the moment
CouchbaseSetting.config_type = :supplier_counters
+3
View File
@@ -0,0 +1,3 @@
# this file is for backwards compatibility of the couchbase-structures gem since version 0.1.0 requires this file
# while couchbase-docstore is already over to the new require 'couchbase-docstore' syntax (kinda)
require 'couchbase-docstore'
+3
View File
@@ -0,0 +1,3 @@
# this file is for backwards compatibility of the couchbase-structures gem since version 0.1.0 requires this file
# while couchbase-settings is custom for now
require 'couchbase-setting'
+3
View File
@@ -0,0 +1,3 @@
# this file is for backwards compatibility of the couchbase-structures gem since version 0.1.0 requires this file
# while couchbase-settings is custom for now
require 'couchbase-setting'
+14
View File
@@ -1,6 +1,20 @@
module Qwaiter
mattr_accessor :event_host
mattr_accessor :broadcaster
extend ActiveSupport::Autoload
autoload :Distribution
autoload :Serializer
autoload :Counter
autoload :Broadcaster
def self.broadcast_user(uid, event, data)
message = {channel: "/user/#{uid}", data: {event: event, data: data}}
broadcaster.broadcast message
end
def self.broadcast_supplier(sid, event, data)
message = {channel: "/supplier/#{sid}", data: {event: event, data: data}}
broadcaster.broadcast message
end
end
+6
View File
@@ -0,0 +1,6 @@
module Qwaiter
module Broadcaster
extend ActiveSupport::Autoload
autoload :Faye
end
end
+10
View File
@@ -0,0 +1,10 @@
module Qwaiter
module Broadcaster
class Faye
def broadcast(message)
@uri ||= URI.parse(Qwaiter.event_host)
Net::HTTP.post_form(@uri, :message => message.to_json)
end
end
end
end
+27
View File
@@ -0,0 +1,27 @@
module Qwaiter
module Counter
mattr_accessor :connection
# mainly for testing purposes
def self.set(key, value)
connection.set(key, value)
end
def self.get(key)
connection.get(key).to_i
end
def self.incr(*args)
connection.incr(*args)
end
def self.decr(*args)
connection.decr(*args)
end
end
end
# use the connection from couchbase-structures/documents
# will be overwritten in the specs since flushing the real
# thing is difficult
Qwaiter::Counter.connection = $cb