require 'itrigga/config/macros' require 'singleton' module Itrigga module Config class Configuration include ::Singleton include Itrigga::Config::Macros def_param( 'constants', { :RAILS_ENV => ( defined?(RAILS_ENV) ? RAILS_ENV : ENV['RAILS_ENV'] || 'development'), :TRIGGA_SHARED_DIR => '/var/www/itrigga/shared' }) def_param('search_tracker', { :host => 'http://localhost:3001', :access_token => 'GGH4672LqctJmNp5LFGG' } ) def_param('sessions', { :expire_in_hours => 24 }) # what server should we scp worker generated sitemaps to def_param('sitemap', { :targets => [:localhost] }) # urls split by application to hit to warm caches def_param('cache_urls', { :trigga_dot_com => ["http://itrigga.com/refresh_stats"] }) def_param( 'timers', :tick_interval_seconds => 60, :specs => [ {:name=>'Update all sources', :cron_string=>"2 * * * *", :job_yaml=>"--- !ruby/object:UpdateSourceJobSchedulerJob {}\n\n"}, {:name=>'Expire items', :cron_string=>"1 0 * * *", :job_yaml=>"--- !ruby/object:ExpireItemsJob \ndatetime: \n"}, {:name=>'Hello World heartbeat', :cron_string=>"* * * * *", :job_yaml=>"--- !ruby/object:HelloWorldJob \noptions: {}\n\n"}, {:name=>'Update item site scores', :cron_string=>"*/10 * * * *", :job_yaml=>"--- !ruby/object:UpdateItemSiteScoresJob \noptions: {}\n\n"}, {:name=>'Issue send_item_subscription_email jobs', :cron_string=>"15 13 * * 5", :job_yaml=>"--- !ruby/object:IssueSendItemSubscriptionEmailJobsJob \noptions: {}\n\n"}, {:name=>'Update Site Popular & Recent Searches', :cron_string=>"*/10 * * * *", :job_yaml=>"--- !ruby/object:UpdateCachedSiteSearchesJobSchedulerJob \noptions: {}\n\n"}, {:name=>'Update Cached Site Tags', :cron_string=>"*/20 * * * *", :job_yaml=>"--- !ruby/object:UpdateCachedSiteTagsJobSchedulerJob \noptions: {}\n\n"}, {:name=>'Update Cached Channel Tags', :cron_string=>"*/20 * * * *", :job_yaml=>"--- !ruby/object:UpdateCachedChannelTagsJobSchedulerJob \noptions: {}\n\n"}, {:name=>'Delete Expired items', :cron_string=>"30 0 * * *", :job_yaml=>"--- !ruby/object:DeleteExpiredItemsJob \ndatetime: \n"}, {:name=>'Delete old benchmark events', :cron_string=>"45 0 * * *", :job_yaml=>"--- !ruby/object:DeleteOldBenchmarkEventsJob \ndatetime: \n"}, {:name=>'Increment Cache Version', :cron_string=>"*/5 * * * *", :job_yaml=>"--- !ruby/object:IncrementCacheVersionJob {}\n\n"}, {:name=>'Activate Items', :cron_string=>"0 4 * * * *", :job_yaml=>"--- !ruby/object:ActivateItemsJob {}\n\n"}, {:name=>'Expire old unallocated items', :cron_string=>"1 0 * * *", :job_yaml=>"--- !ruby/object:ExpireOldUnallocatedItemsJob \ndatetime: \n"}, {:name=>'Clear old sessions', :cron_string=>"0 3 * * *", :job_yaml=>"--- !ruby/object:ClearSessionsJob {} \n\n"}, {:name=>'Update Seatwave Cached Performances', :cron_string=>"0 2 * * *", :job_yaml=>"--- !ruby/object:UpdateSeatwaveCachedPerformancesJob {} \n\n"}, {:name=>'Optimize all Tables', :cron_string=>"30 3 * * *", :job_yaml=>"--- !ruby/object:OptimizeTableJobSchedulerJob {}\n\n"}, {:name=>'Generate All Sitemaps', :cron_string=>"0 */4 * * *", :job_yaml=>"--- !ruby/object:GenerateAllSitemapsJob {}\n\n"}, {:name=>'Warm the itrigga.com stats caches', :cron_string=>"0 2,14 * * *", :job_yaml=>"--- !ruby/object:WarmTriggaDotComCachesJob {}\n\n"}, {:name=>'Schedule item email deliveries', :cron_string=>"0 */1 * * * *", :job_yaml=>"--- !ruby/object:SendChannelItemsEmailJobSchedulerJob {}\n\n"}, {:name=>'Optimize solr index', :cron_string=>"0 2 * * * *", :job_yaml=>"--- !ruby/object:OptimizeSolrIndexJob {}\n\n"} ] ) def_param( 'memcache', :enabled => true, :options => { :c_threshold => 10_000, :compression => true, :debug => false, :namespace => "trigga_default", :readonly => false, :urlencode => false }, :servers => 'localhost:11211', :lifetime_seconds => 60 ) def_param( 'sites', [] ) def_param( 'facebook', :perms => "email,publish_stream,offline_access,read_stream" ) def_param( 'processes', :web => { :port => 3000, :servers => 3, :request_timeout => 30 }, :solr => { :paths => { :root=> "vendor/plugins/acts_as_solr/solr/", :instances_root => "../solr/instances", :data=> "../solr/data" }, :url => "http://127.0.0.1:8983/solr", :jvm_options=> "" # for production: -server -d64 -Xmx1024M -Xms64M }, :broker => { :options => { :host => '127.0.0.1', :port => 5672, :vhost => 'itrigga.com', :user => 'trigga', :pass => 'n0sp00n3r15m5plz', :timeout => 5, :logging => false, # <- extremely verbose protocol logging, :prefetch => 1 # <- maximum of this many msgs to be sent to the client at any one time (stop rabbit flooding the worker, also stop messages disappearing when client dies) }, :connection_check_seconds => 5, :queues => [ {:name=>'priority_high', :binding => { :exchange_name=>'jobs_exchange', :key => 'trigga.jobs.priority.high.*' }, :options=>{:durable=>true, :ack=>true} # <- ack=true says to acknowledge each msg (otherwise they can get lost) }, {:name=>'priority_med', :binding => { :exchange_name=>'jobs_exchange', :key => 'trigga.jobs.priority.med.*' }, :options=>{:durable=>true, :ack=>true} # <- ack=true says to acknowledge each msg (otherwise they can get lost) }, {:name=>'priority_low', :binding => { :exchange_name=>'jobs_exchange', :key => 'trigga.jobs.priority.low.*' }, :options=>{:durable=>true, :ack=>true} # <- ack=true says to acknowledge each msg (otherwise they can get lost) } ], :exchanges => [ { :name=>'jobs_exchange', :key_root=>'trigga', :options=>{:type=>:topic, :passive=>false, :durable=>true, :auto_delete => false }, :default_msg_options=>{:mandatory => true, :immediate=>false, :persistent => true} } ], :default_exchange_name => 'jobs_exchange', :unique_process_search_string => 'rabbitmq-server' }, :job_resubmitter=> { :tick_interval_seconds => 10, :max_batch_size => 100 }, :timer => { :tick_interval_seconds => 10, :reactivate_stale_seconds => 14400, :reactivate_old_queued_seconds => 14400 }, # worker's queue_names determines which queues (defined in the broker config above) # each worker process will subscribe to. # the default 'worker' will subscribe to them all, # but you can have separate hi/med/low priority workers to prevent # workers getting swamped by one type of slow-running job (e.g. UpdateItemLinksJob) :worker => { :queue_names=>['priority_high', 'priority_med', 'priority_low'] }, :"worker-hi" => { :queue_names=>['priority_high'] }, :"worker-med" => { :queue_names=>['priority_med'] }, :"worker-low" => { :queue_names=>['priority_low'] }, :term_extractor => { :port => 4567, :url => "http://localhost:4567/terms" }, :memcached => { :port => 11212, :max_mem_mb => 64, :user => 'root' } ) def_param( 'processes_to_start', [:broker, :solr, :memcached, :web, :"worker", :timer, :scheduled_job_resubmitter, :term_extractor] # <- start these processes, in this order ) def_param( 'ssh_hosts_to_monitor', [:localhost] ) def_param( 'monit_templates_to_render', [] ) def_param( 'cron_templates_to_render', [] ) def_param( 'monitoring_templates_to_render', [] ) def_param('mysql', :replication_user => { :username => "ws_status", :password => "ws_status123" } ) def_param( 'hosts', [ { :host => "localhost", :display_name => "localhost", :port => 22, :user => ENV["USER"], :ssh_key_path => nil, :mysql_user => "tn", :mysql_pwd => "n0sp00n3r15m5plz", :types => [:db_slave_stats, :process_stats, :broker_stats] } ] ) # Aliases # TODO: refactor refs to these def rabbit_mq; processes[:broker]; end def web_service_term_extractor; processes[:term_extractor]; end def scheduled_job_submitter; processes[:job_resubmitter]; end def environment RAILS_ENV end def environment_type case environment when /test/: 'test' when /development/: 'development' else 'production' end end def is_test?; environment_type == 'test'; end def is_production?; environment_type == 'production'; end def is_development?; environment_type == 'development'; end def exchange_config(name) @rabbit_mq[:exchanges].find{ |e| e[:name] == name } end end end end