Commit da69b935 by zmj

减少配置

parent 37413133
...@@ -7,7 +7,7 @@ class PushsController < ApplicationController ...@@ -7,7 +7,7 @@ class PushsController < ApplicationController
param! :app_id, String, required: true param! :app_id, String, required: true
param! :app_secret, String, required: true param! :app_secret, String, required: true
app_setting = AppSettings.send(params[:app_name].to_sym) rescue {} app_setting = Settings.send(params[:app_name].to_sym) rescue {}
if app_setting['app_id'] == params[:app_id] && app_setting['app_secret'] == params[:app_secret] if app_setting['app_id'] == params[:app_id] && app_setting['app_secret'] == params[:app_secret]
render json: { code: 0, message: 'success', token: Token.generate_token(params[:app_name]), ttl: Token.ttl(params[:app_name])} render json: { code: 0, message: 'success', token: Token.generate_token(params[:app_name]), ttl: Token.ttl(params[:app_name])}
else else
......
class AppSettings < Settingslogic
source "#{Rails.root}/config/app.yml"
namespace Rails.env
end
\ No newline at end of file
...@@ -22,7 +22,7 @@ module Push ...@@ -22,7 +22,7 @@ module Push
nsp_ctx = { nsp_ctx = {
ver: '1', ver: '1',
appId: PushSettings.huawei['app_id'] appId: Settings.huawei['app_id']
} }
url = PUSH_URL + "?nsp_ctx=#{CGI::escape(nsp_ctx.to_json)}" url = PUSH_URL + "?nsp_ctx=#{CGI::escape(nsp_ctx.to_json)}"
post(url, body) post(url, body)
...@@ -67,8 +67,8 @@ module Push ...@@ -67,8 +67,8 @@ module Push
def req_token def req_token
body = { body = {
grant_type: 'client_credentials', grant_type: 'client_credentials',
client_id: PushSettings.huawei['app_id'], client_id: Settings.huawei['app_id'],
client_secret: PushSettings.huawei['app_secret'] client_secret: Settings.huawei['app_secret']
} }
post(TOKEN_URL, body) post(TOKEN_URL, body)
end end
......
...@@ -43,9 +43,9 @@ module Push ...@@ -43,9 +43,9 @@ module Push
def pusher def pusher
@pusher ||= IGeTui.pusher( @pusher ||= IGeTui.pusher(
PushSettings.igetui['app_id'], Settings.igetui['app_id'],
PushSettings.igetui['app_key'], Settings.igetui['app_key'],
PushSettings.igetui['master_secret'] Settings.igetui['master_secret']
) )
end end
...@@ -64,7 +64,7 @@ module Push ...@@ -64,7 +64,7 @@ module Push
@template = "IGeTui::#{template_type}".constantize.new @template = "IGeTui::#{template_type}".constantize.new
case template_type case template_type
when 'NotificationTemplate', 'NotyPopLoadTemplate', 'LinkTemplate' when 'NotificationTemplate', 'NotyPopLoadTemplate', 'LinkTemplate'
@template_data.reverse_merge!(PushSettings.igetui['template_base']) @template_data.reverse_merge!(Settings.igetui['template_base'])
@template_data.each do |k, v| @template_data.each do |k, v|
@template.send("#{k}=", v) @template.send("#{k}=", v)
......
...@@ -30,7 +30,7 @@ module Push ...@@ -30,7 +30,7 @@ module Push
# 0 表示通知栏消息, 1 表示透传消息 # 0 表示通知栏消息, 1 表示透传消息
def config def config
{ {
restricted_package_name: PushSettings.xiaomi['package_name'], restricted_package_name: Settings.xiaomi['package_name'],
pass_through: 1, pass_through: 1,
title: 'xiaomi push', title: 'xiaomi push',
description: 'xiaomi push', description: 'xiaomi push',
...@@ -42,7 +42,7 @@ module Push ...@@ -42,7 +42,7 @@ module Push
response = HTTParty.post(PUSH_URL, query: params, response = HTTParty.post(PUSH_URL, query: params,
headers: { headers: {
'Accept' => 'application/json;', 'Accept' => 'application/json;',
"Authorization": "key=#{PushSettings.xiaomi['app_secret']}" "Authorization": "key=#{Settings.xiaomi['app_secret']}"
}, },
timeout: 5) timeout: 5)
Push::Log.info("xiaomi_push: \n url: #{PUSH_URL}\n params: #{params}\n response: #{response}") Push::Log.info("xiaomi_push: \n url: #{PUSH_URL}\n params: #{params}\n response: #{response}")
......
class PushSettings < Settingslogic
source "#{Rails.root}/config/push.yml"
namespace Rails.env
end
\ No newline at end of file
defaults: &defaults
crm:
app_id: 'ba9936cf01aaf888'
app_secret: 'cd855e8ea1ff27034425e502d974eb3a'
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
\ No newline at end of file
...@@ -10,12 +10,8 @@ set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production')) ...@@ -10,12 +10,8 @@ set :puma_env, fetch(:rack_env, fetch(:rails_env, 'production'))
set :linked_files, %w[ set :linked_files, %w[
config/credentials.yml.enc config/credentials.yml.enc
config/puma.rb
config/master.key config/master.key
config/sidekiq.yml
config/push.yml
config/settings.yml config/settings.yml
config/app.yml
] ]
set :linked_dirs, %w[ set :linked_dirs, %w[
......
# Puma can serve each request in a thread from an internal thread pool. require 'json'
# The `threads` method setting takes two numbers: a minimum and maximum.
# Any libraries that use thread pools should be configured to match file = File.read('config/server.json')
# the maximum value specified for Puma. Default is set to 5 threads for minimum deploy_config = JSON.parse(file)
# and maximum; this matches the default thread size of Active Record. port deploy_config['http_port']
# environment 'production'
threads_count = ENV.fetch("RAILS_MAX_THREADS") { 5 } workers 2
threads threads_count, threads_count threads 0, 16
bind "unix://#{deploy_config['deploy_to']}/shared/tmp/sockets/push-puma.sock"
# Specifies the `port` that Puma will listen on to receive requests; default is 3000. pidfile "#{deploy_config['deploy_to']}/shared/tmp/pids/puma.pid"
# state_path "#{deploy_config['deploy_to']}/shared/tmp/pids/puma.state"
port ENV.fetch("PORT") { 3000 } stdout_redirect "#{deploy_config['deploy_to']}/current/log/puma_error.log", "#{deploy_config['deploy_to']}/current/log/puma_access.log", true
# Specifies the `environment` that Puma will run in.
#
environment ENV.fetch("RAILS_ENV") { "development" }
# Specifies the number of `workers` to boot in clustered mode.
# Workers are forked webserver processes. If using threads and workers together
# the concurrency of the application would be max `threads` * `workers`.
# Workers do not work on JRuby or Windows (both of which do not support
# processes).
#
# workers ENV.fetch("WEB_CONCURRENCY") { 2 }
# Use the `preload_app!` method when specifying a `workers` number.
# This directive tells Puma to first boot the application and load code
# before forking the application. This takes advantage of Copy On Write
# process behavior so workers use less memory.
#
# preload_app!
# Allow puma to be restarted by `rails restart` command.
plugin :tmp_restart plugin :tmp_restart
igetui:
app_id: "APP_ID"
app_key: "APP_KEY"
app_secret: "APP_SECRET"
master_secret: "MASTER_SECRET"
template_base:
logo: "ik_logo.png"
logo_url: "http://www.ikcrm.com/assets/img/ik_logo.png"
title: ""
text: ""
huawei:
app_id: "****"
app_secret: "****"
\ No newline at end of file
...@@ -6,6 +6,32 @@ defaults: &defaults ...@@ -6,6 +6,32 @@ defaults: &defaults
job_db: 1 job_db: 1
cache_db: 2 cache_db: 2
timeout: 5000 timeout: 5000
igetui:
app_id: "Xz8goKcReVA530Skeex4G6"
app_key: "uqesFB0v4u7lQP5BnOpwy9"
app_secret: "epBoJk7Z4bAOk1XZIzSHl7"
master_secret: "NlQSSDyPjR7ElA6YYLtgI9"
template_base:
logo: "ik_logo.png"
logo_url: "http://www.ikcrm.com/assets/img/ik_logo.png"
title: ""
text: ""
huawei:
app_id: "10471990"
app_secret: "ocr55sr7xj88oky93xlv0pkuuykx060j"
xiaomi:
app_id: '2882303761517266621'
app_key: '5881726643621'
app_secret: 'tQWrpyjb+47hdH/MSmfMGQ==' # 请求的header中用到了
package_name: 'com.vcooline.aike'
crm:
app_id: 'ba9936cf01aaf888'
app_secret: 'cd855e8ea1ff27034425e502d974eb3a'
development: development:
<<: *defaults <<: *defaults
log_cache: true log_cache: true
......
APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..')) APP_ROOT = File.expand_path(File.join(File.dirname(__FILE__), '..'))
QUEUES = { QUEUES = {
push: { concurrency: 10, workers: 2, memory: 1000 } push: { concurrency: 10, workers: 4, memory: 1000 }
} }
pid_index = 0 pid_index = 0
QUEUES.each { |queue_name, queue_conf| QUEUES.each { |queue_name, queue_conf|
......
:concurrency: 5 :concurrency: 5
development:
:concurrency: 10
:queues: :queues:
- push - push
:timeout: 600
development:
:concurrency: 2
staging:
:concurrency: 2
production:
:concurrency: 6
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment