dockerize faye and counters
This commit is contained in:
+1
-1
@@ -5,7 +5,7 @@
|
||||
# git config --global core.excludesfile ~/.gitignore_global
|
||||
|
||||
# Ignore bundler config
|
||||
/.bundle
|
||||
.bundle
|
||||
|
||||
# Ignore the default SQLite database.
|
||||
/db/*.sqlite3
|
||||
|
||||
BIN
Binary file not shown.
@@ -21,6 +21,7 @@ App.ApplicationController = Ember.Controller.extend
|
||||
@set 'notice', ''
|
||||
).observes('currentPath')
|
||||
events:
|
||||
notify: (notification) -> @set 'notice', notification.message
|
||||
list_helped: -> @set 'list.needs_help', false
|
||||
list_needs_help: -> @set 'list.needs_help', true # incoming from other users
|
||||
list_is_paid: -> @set 'list.needs_payment', false
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
class DashboardController < ApplicationController
|
||||
class DashboardController < ApplicationController
|
||||
layout 'theme1'
|
||||
before_action :allow_all_origins, only: :error_report
|
||||
|
||||
@@ -13,6 +13,10 @@
|
||||
render nothing: true
|
||||
end
|
||||
|
||||
def scan
|
||||
|
||||
end
|
||||
|
||||
def close_window
|
||||
render layout: false
|
||||
end
|
||||
|
||||
@@ -52,6 +52,14 @@ class List
|
||||
}
|
||||
}], reduce_function: '_sum'
|
||||
|
||||
view :active_users_view, type: :custom, map_function: %[function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.state == 'active'){
|
||||
doc.user_ids && doc.user_ids.forEach(function(uid){
|
||||
emit([doc.supplier_id, uid], 1);
|
||||
})
|
||||
}
|
||||
}], reduce_function: '_sum'
|
||||
|
||||
view :for_user_view, type: :custom, map_function: %|function(doc){
|
||||
if(doc.ruby_class == 'List' && doc.user_ids && doc.user_ids.length){
|
||||
doc.user_ids.forEach(function(uid){
|
||||
|
||||
+1
-1
@@ -87,7 +87,7 @@ Qwaiter::Application.routes.draw do
|
||||
#get '/bars-restaurants' => 'dashboard#bars_restaurants', as: :bars_restaurants
|
||||
#get '/clients' => 'dashboard#clients'
|
||||
#get '/contact' => 'dashboard#contact'
|
||||
get '/s' => redirect('/scan'), as: :scan
|
||||
get '/s' => 'dashboard#scan', as: :scan
|
||||
|
||||
# DEVELOPMENT ONLY
|
||||
get '/qr' => 'dashboard#qr'
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
FROM ruby:2.2.0
|
||||
|
||||
# throw errors if Gemfile has been modified since Gemfile.lock
|
||||
RUN bundle config --global frozen 1
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
|
||||
# Test
|
||||
#RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
# Standard
|
||||
#RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
#RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
# Specific
|
||||
#RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY Gemfile /usr/src/app/
|
||||
COPY Gemfile.lock /usr/src/app/
|
||||
#COPY vendor/cache /usr/src/app/vendor/cache
|
||||
#RUN bundle install --local
|
||||
RUN rm -rf /usr/src/app/.bundle
|
||||
RUN bundle install
|
||||
|
||||
COPY . /usr/src/app
|
||||
|
||||
EXPOSE 9022
|
||||
CMD ["ruby", "drb_counter.rb"]
|
||||
@@ -0,0 +1,4 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem "couchrest"
|
||||
gem "pry"
|
||||
@@ -0,0 +1,196 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
coderay (1.1.0)
|
||||
couchrest (1.2.0)
|
||||
mime-types (~> 1.15)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
multi_json (~> 1.0)
|
||||
rest-client (~> 1.6.1)
|
||||
method_source (0.8.2)
|
||||
mime-types (1.25.1)
|
||||
multi_json (1.10.1)
|
||||
pry (0.10.1)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
rdoc (4.2.0)
|
||||
rest-client (1.6.8)
|
||||
mime-types (~> 1.16)
|
||||
rdoc (>= 2.4.2)
|
||||
slop (3.6.0)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
couchrest
|
||||
pry
|
||||
@@ -0,0 +1,8 @@
|
||||
views:
|
||||
by_supplier_id_and_state:
|
||||
map: |
|
||||
function(doc) {
|
||||
if(doc.ruby_class && doc.ruby_class == 'Order') emit([doc['supplier_id'], doc['state']], 1);
|
||||
}
|
||||
reduce: _sum
|
||||
language: "javascript"
|
||||
@@ -1,6 +1,8 @@
|
||||
#!/usr/bin/env ruby
|
||||
# Make drb server
|
||||
require 'rubygems'
|
||||
require 'drb'
|
||||
require 'pry'
|
||||
#require File.expand_path('../lib/in_memory_q_counter', File.dirname(__FILE__))
|
||||
# This is a non thread safe replacement for the
|
||||
# couchbase counter mechanism since every test needs
|
||||
@@ -16,14 +18,18 @@ class InMemoryQCounter
|
||||
end
|
||||
|
||||
def get(key, options = {})
|
||||
store[key]
|
||||
value = store[key]
|
||||
debug "Get key #{key} (#{value})"
|
||||
value
|
||||
end
|
||||
|
||||
def set(key, value)
|
||||
debug "Set key #{key} to #{value}"
|
||||
store[key] = value
|
||||
end
|
||||
|
||||
def incr(key, options = {})
|
||||
debug "Increment key #{key}"
|
||||
# store[key] ||= options[:initial].to_i
|
||||
# store[key] += 1
|
||||
if store[key]
|
||||
@@ -34,6 +40,7 @@ class InMemoryQCounter
|
||||
end
|
||||
|
||||
def decr(key, options = {})
|
||||
debug "Decrement key #{key}"
|
||||
# store[key] ||= options[:initial].to_i
|
||||
# store[key] -= 1
|
||||
if store[key]
|
||||
@@ -44,22 +51,45 @@ class InMemoryQCounter
|
||||
end
|
||||
|
||||
def flush
|
||||
debug "Flushing store"
|
||||
store.clear
|
||||
end
|
||||
|
||||
def debug(message)
|
||||
puts message
|
||||
end
|
||||
|
||||
def reload_stats!
|
||||
require 'yaml'
|
||||
require 'couchrest'
|
||||
require 'pry'
|
||||
binding.pry
|
||||
couch_settings_path = File.join(ENV['MOZO_PATH'], 'config/couchdb.yml')
|
||||
couch_settings_path = 'config/couchdb.yml'
|
||||
puts "Couch settings path: #{couch_settings_path}"
|
||||
puts "Environment: #{environment.inspect}"
|
||||
couch_settings = YAML.load_file(couch_settings_path)[environment]
|
||||
database = couch_settings['database']
|
||||
db = CouchRest.database(database)
|
||||
view_result = db.view("_design/order/_view/by_supplier_id_and_state", reduce: true, group_level: 2)
|
||||
design_doc = "_design/order_counter"
|
||||
view_path = File.join design_doc, "_view/by_supplier_id_and_state"
|
||||
tries = 0
|
||||
begin
|
||||
view_result = db.view(view_path, reduce: true, group: true, group_level: 2)
|
||||
rescue RestClient::ResourceNotFound => e
|
||||
puts "Database view #{view_path} not found"
|
||||
design_doc_path = File.expand_path('../couchdb_design.yml', __FILE__)
|
||||
doc = YAML.load_file design_doc_path
|
||||
doc['_id'] = design_doc
|
||||
db.save_doc(doc)
|
||||
if tries < 3
|
||||
tries += 1
|
||||
retry
|
||||
else
|
||||
raise e
|
||||
end
|
||||
# view not available, initialize as zero
|
||||
end
|
||||
counts = view_result ? view_result['rows'] : nil
|
||||
puts "Initialize with: #{counts.to_yaml}"
|
||||
if counts
|
||||
counts.each do |count_spec|
|
||||
supplier_id, order_state = count_spec['key']
|
||||
@@ -70,17 +100,11 @@ class InMemoryQCounter
|
||||
end
|
||||
end
|
||||
end
|
||||
rescue RestClient::ResourceNotFound
|
||||
# view not available, initialize as zero
|
||||
rescue => e
|
||||
raise e
|
||||
end
|
||||
end
|
||||
require 'drb'
|
||||
require 'daemons'
|
||||
drb_port = 9022
|
||||
Daemons.run_proc('DRBcounter', dir_mode: :normal, dir: File.expand_path("#{File.dirname(__FILE__)}/../tmp/pids")) do
|
||||
environment = (%w[production staging development test] & ARGV).first
|
||||
DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment)
|
||||
DRb.thread.join
|
||||
end
|
||||
environment = (%w[production staging development test] & ARGV).first || 'development'
|
||||
DRb.start_service "druby://:#{drb_port}", InMemoryQCounter.new(reload_stats: true, environment: environment)
|
||||
DRb.thread.join
|
||||
@@ -0,0 +1,29 @@
|
||||
FROM ruby:2.2.0
|
||||
|
||||
# throw errors if Gemfile has been modified since Gemfile.lock
|
||||
RUN bundle config --global frozen 1
|
||||
|
||||
RUN mkdir -p /usr/src/app
|
||||
|
||||
WORKDIR /usr/src/app
|
||||
RUN apt-get update
|
||||
# Test
|
||||
#RUN apt-get update && apt-get install -y qt5-default libqt5webkit5-dev --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
# Standard
|
||||
#RUN apt-get update && apt-get install -y nodejs --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
#RUN apt-get update && apt-get install -y mysql-client postgresql-client sqlite3 --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
# Specific
|
||||
#RUN apt-get update && apt-get install -y dos2unix --no-install-recommends && rm -rf /var/lib/apt/lists/*
|
||||
|
||||
COPY Gemfile /usr/src/app/
|
||||
COPY Gemfile.lock /usr/src/app/
|
||||
#COPY vendor/cache /usr/src/app/vendor/cache
|
||||
#RUN bundle install --local
|
||||
RUN rm -rf /usr/src/app/.bundle
|
||||
RUN bundle install
|
||||
|
||||
COPY . /usr/src/app
|
||||
ENV FAYE_PORT=9296
|
||||
EXPOSE $FAYE_PORT
|
||||
CMD thin start -R config.ru -p $FAYE_PORT
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
source 'https://rubygems.org'
|
||||
|
||||
gem "faye"
|
||||
gem "thin"
|
||||
gem "pry"
|
||||
@@ -0,0 +1,51 @@
|
||||
GEM
|
||||
remote: https://rubygems.org/
|
||||
specs:
|
||||
addressable (2.3.7)
|
||||
coderay (1.1.0)
|
||||
cookiejar (0.3.2)
|
||||
daemons (1.1.9)
|
||||
em-http-request (1.1.2)
|
||||
addressable (>= 2.3.4)
|
||||
cookiejar
|
||||
em-socksify (>= 0.3)
|
||||
eventmachine (>= 1.0.3)
|
||||
http_parser.rb (>= 0.6.0)
|
||||
em-socksify (0.3.0)
|
||||
eventmachine (>= 1.0.0.beta.4)
|
||||
eventmachine (1.0.7)
|
||||
faye (1.1.0)
|
||||
cookiejar (>= 0.3.0)
|
||||
em-http-request (>= 0.3.0)
|
||||
eventmachine (>= 0.12.0)
|
||||
faye-websocket (>= 0.9.1)
|
||||
multi_json (>= 1.0.0)
|
||||
rack (>= 1.0.0)
|
||||
websocket-driver (>= 0.5.1)
|
||||
faye-websocket (0.9.2)
|
||||
eventmachine (>= 0.12.0)
|
||||
websocket-driver (>= 0.5.1)
|
||||
http_parser.rb (0.6.0)
|
||||
method_source (0.8.2)
|
||||
multi_json (1.10.1)
|
||||
pry (0.10.1)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.8.1)
|
||||
slop (~> 3.4)
|
||||
rack (1.6.0)
|
||||
slop (3.6.0)
|
||||
thin (1.6.3)
|
||||
daemons (~> 1.0, >= 1.0.9)
|
||||
eventmachine (~> 1.0)
|
||||
rack (~> 1.0)
|
||||
websocket-driver (0.5.1)
|
||||
websocket-extensions (>= 0.1.0)
|
||||
websocket-extensions (0.1.1)
|
||||
|
||||
PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
faye
|
||||
pry
|
||||
thin
|
||||
@@ -6,14 +6,18 @@ db:
|
||||
- 5984
|
||||
net: host
|
||||
counters:
|
||||
image: ruby:2.2
|
||||
web:
|
||||
build: .
|
||||
#command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb
|
||||
command: rails s
|
||||
build: drb_counter
|
||||
net: host
|
||||
volumes:
|
||||
- .:/usr/src/app
|
||||
ports:
|
||||
- "3000:3000"
|
||||
#links:
|
||||
# #- db
|
||||
- config:/usr/src/app/config
|
||||
faye:
|
||||
build: faye
|
||||
net: host
|
||||
#web:
|
||||
#build: .
|
||||
#command: bundle exec unicorn -p 3000 -c ./config/unicorn.rb
|
||||
#command: rails s
|
||||
#volumes:
|
||||
#- .:/usr/src/app
|
||||
#ports:
|
||||
#- "3000:3000"
|
||||
|
||||
Reference in New Issue
Block a user