Module: Jason
- Defined in:
- lib/jason.rb,
lib/jason/engine.rb,
lib/jason/version.rb
Defined Under Namespace
Modules: Publisher Classes: ApiModel, Broadcaster, Channel, ConditionsMatcher, ConsistencyChecker, Engine, Error, GraphHelper, IncludesHelper, JasonController, LuaGenerator, MissingCacheError, OutboundMessageQueueWorker, PusherController, Subscription
Constant Summary collapse
- VERSION =
"0.8.7"
Class Method Summary collapse
- .init ⇒ Object
-
.setup {|_self| ... } ⇒ Object
this function maps the vars from your app into your engine.
Class Method Details
.init ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/jason.rb', line 39 def self.init # Don't run in AR migration / generator etc. return if $PROGRAM_NAME == '-e' || ActiveRecord::Base.connection.migration_context.needs_migration? # Check if the schema has changed since last time app was started. If so, do some work to ensure cache contains the correct data got_lock = $redis_jason.set('jason:schema:lock', '1', nx: true, ex: 3600) # Basic lock mechanism for multi-process environments return if !got_lock previous_schema = JSON.parse($redis_jason.get('jason:last_schema') || '{}') current_schema = Jason.schema.deep_stringify_keys.deep_transform_values { |v| v.is_a?(Symbol) ? v.to_s : v } current_schema.each do |model, config| if config != previous_schema[model] puts "Config changed for #{model}" puts "Old config was #{previous_schema[model]}" puts "New config is #{config}" puts "Wiping cache for #{model}" $redis_jason.del("jason:cache:#{model}") puts "Done" end end $redis_jason.set('jason:last_schema', current_schema.to_json) ensure $redis_jason.del('jason:schema:lock') end |
.setup {|_self| ... } ⇒ Object
this function maps the vars from your app into your engine
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/jason.rb', line 68 def self.setup(&block) yield self $redis_jason = self.redis || ::ConnectionPool::Wrapper.new(size: 5, timeout: 3) { ::Redis.new(url: ENV['REDIS_URL']) } if ![:action_cable, :pusher].include?(self.transport_service) raise "Unknown transport service '#{self.transport_service}' specified" end if self.transport_service == :pusher && self.pusher.blank? raise "Pusher specified as transport service but no Pusher client provided. Please configure with config.pusher = Pusher::Client.new(...)" end init end |