jason-rails 0.6.6 → 0.6.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 627690fe30b3378cde9c9f148cc8d8d6941bcd540cbbe4777898fa8917f86dc8
4
- data.tar.gz: bd3af795626563a049c02045b8dc82018882067f9b2d582e4152e1bd6b34af4c
3
+ metadata.gz: 48abc57aac9f4529a93812d46422ac21d48e58432fc21e570f1801b84a3ac436
4
+ data.tar.gz: ac21dab5464e5dd254a1a223a80581c1410c928bab4c0fbc9fe32cdfedb7c474
5
5
  SHA512:
6
- metadata.gz: 4ed1a231161d3eafc616549eebd38c531c29203842f1ab8d0697e953f0d9af8a4766285b8733fa0d92ae1cd7893560f3d660c920385c0b7335f41cfa5f8c9387
7
- data.tar.gz: 7289710ebc49e0c53c7bdd52106d0e8153bc4505d98b26251966ccff63895e4c6c5a6ac2009b904bbf3d7d3b552c71ffebe0f17786998aaf9eaedafbf12710fb
6
+ metadata.gz: '09c42d2b035af32efdc006224e3e81fa398d2327199845640ff7c710c7cecbd0c5edd9d18e441b5b3fefb2a356f45159c77194ed72f866880171071fb302c422'
7
+ data.tar.gz: 1b5f4f16a5032ca96f8106dc4fff8c8a1a1d5792392b4ed28ad9f1c8974848dec5359e4bb0bc675463cc923e5f77552b6bcfda6c733bf72bb66f156648ce521c
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## v0.6.6
2
+ - Fix: don't run the schema change detection and cache rebuild inside rake tasks or migrations
3
+
1
4
  ## v0.6.5
2
5
  - Added `reset!` and `reset!(hard: true)` methods to `Subscription`. Reset will load the IDs that should be part of the subscription from the database, and ensure that the graph matches those. It then re-broadcasts the payloads to all connected clients. Hard reset will do the same, but also clear all cached IDs and subscription hooks on instances - this is equivalent from starting from scratch.
3
6
  - Added `enforce: boolean` option to GraphHelper
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- jason-rails (0.6.4)
4
+ jason-rails (0.6.6)
5
5
  connection_pool (>= 2.2.3)
6
6
  jsondiff
7
7
  rails (>= 5)
@@ -93,7 +93,7 @@ GEM
93
93
  mini_mime (1.0.2)
94
94
  mini_portile2 (2.5.0)
95
95
  minitest (5.14.3)
96
- nio4r (2.5.4)
96
+ nio4r (2.5.5)
97
97
  nokogiri (1.11.1)
98
98
  mini_portile2 (~> 2.5.0)
99
99
  racc (~> 1.4)
@@ -153,6 +153,10 @@ GEM
153
153
  rspec-mocks (~> 3.10)
154
154
  rspec-support (~> 3.10)
155
155
  rspec-support (3.10.0)
156
+ sidekiq (6.1.3)
157
+ connection_pool (>= 2.2.2)
158
+ rack (~> 2.0)
159
+ redis (>= 4.2.0)
156
160
  sprockets (4.0.2)
157
161
  concurrent-ruby (~> 1.0)
158
162
  rack (> 1, < 3)
@@ -178,6 +182,7 @@ DEPENDENCIES
178
182
  rake (~> 12.0)
179
183
  rspec (~> 3.0)
180
184
  rspec-rails
185
+ sidekiq
181
186
  sqlite3
182
187
 
183
188
  BUNDLED WITH
@@ -1,4 +1,4 @@
1
- class Jason::ApiController < ::ApplicationController
1
+ class Jason::JasonController < ::ApplicationController
2
2
  before_action :load_and_authorize_subscription, only: [:create_subscription, :remove_subscription, :get_payload]
3
3
  # config seems to be a reserved name, resulting in infinite loop
4
4
  def configuration
@@ -1,4 +1,4 @@
1
- class Jason::Api::PusherController < ApplicationController
1
+ class Jason::PusherController < ApplicationController
2
2
  skip_before_action :verify_authenticity_token
3
3
 
4
4
  def auth
@@ -0,0 +1,21 @@
1
+ class Jason::OutboundMessageQueueWorker
2
+ include Sidekiq::Worker
3
+
4
+ def perform
5
+ batch = get_batch
6
+ return if batch.size == 0
7
+
8
+ Jason.pusher.trigger_batch(batch)
9
+ end
10
+
11
+ private
12
+
13
+ def get_batch
14
+ batch_json = $redis_jason.multi do |r|
15
+ r.lrange("jason:outbound_message_queue", 0, 9) # get first 10 elements
16
+ r.ltrim("jason:outbound_message_queue", 10, -1) # delete first 10 elements
17
+ end[0]
18
+
19
+ batch_json.map { |event| JSON.parse(event).with_indifferent_access } # Pusher wants symbol keys
20
+ end
21
+ end
data/client/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jamesr2323/jason",
3
- "version": "0.6.5",
3
+ "version": "0.6.7",
4
4
  "module": "./lib/index.js",
5
5
  "types": "./lib/index.d.ts",
6
6
  "scripts": {
data/config/routes.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  Jason::Engine.routes.draw do
2
- get '/api/config', to: 'api#configuration'
3
- post '/api/action', to: 'api#action'
4
- post '/api/create_subscription', to: 'api#create_subscription'
5
- post '/api/remove_subscription', to: 'api#remove_subscription'
6
- post '/api/get_payload', to: 'api#get_payload'
7
- post '/api/pusher/auth', to: 'api/pusher#auth'
2
+ get '/api/config', to: 'jason#configuration'
3
+ post '/api/action', to: 'jason#action'
4
+ post '/api/create_subscription', to: 'jason#create_subscription'
5
+ post '/api/remove_subscription', to: 'jason#remove_subscription'
6
+ post '/api/get_payload', to: 'jason#get_payload'
7
+ post '/api/pusher/auth', to: 'pusher#auth'
8
8
  end
data/jason-rails.gemspec CHANGED
@@ -31,4 +31,5 @@ Gem::Specification.new do |spec|
31
31
  spec.add_development_dependency "rspec-rails"
32
32
  spec.add_development_dependency "sqlite3"
33
33
  spec.add_development_dependency "pry"
34
+ spec.add_development_dependency "sidekiq"
34
35
  end
data/lib/jason.rb CHANGED
@@ -24,11 +24,13 @@ module Jason
24
24
  self.mattr_accessor :pusher_region
25
25
  self.mattr_accessor :pusher_channel_prefix
26
26
  self.mattr_accessor :authorization_service
27
+ self.mattr_accessor :sidekiq_queue
27
28
 
28
29
  self.schema = {}
29
30
  self.transport_service = :action_cable
30
31
  self.pusher_region = 'eu'
31
32
  self.pusher_channel_prefix = 'jason'
33
+ self.sidekiq_queue = 'default'
32
34
 
33
35
  def self.init
34
36
  # Don't run in AR migration / generator etc.
@@ -13,7 +13,8 @@ class Jason::Broadcaster
13
13
  if Jason.transport_service == :action_cable
14
14
  ActionCable.server.broadcast(channel, message)
15
15
  elsif Jason.transport_service == :pusher
16
- Jason.pusher.trigger(pusher_channel_name, 'changed', message)
16
+ $redis_jason.rpush("jason:outbound_message_queue", { channel: pusher_channel_name, name: 'changed', data: message }.to_json)
17
+ Jason::OutboundMessageQueueWorker.perform_async
17
18
  end
18
19
  end
19
20
  end
@@ -42,7 +42,9 @@ module Jason::Publisher
42
42
  # - TODO: The value of an instance changes so that it enters/leaves a subscription
43
43
 
44
44
  # TODO: Optimize this, by caching associations rather than checking each time instance is saved
45
- jason_assocs = self.class.reflect_on_all_associations(:belongs_to).select { |assoc| assoc.klass.respond_to?(:has_jason?) }
45
+ jason_assocs = self.class.reflect_on_all_associations(:belongs_to)
46
+ .reject { |assoc| assoc.polymorphic? } # Can't get the class name of a polymorphic association, by
47
+ .select { |assoc| assoc.klass.respond_to?(:has_jason?) }
46
48
  jason_assocs.each do |assoc|
47
49
  if previous_changes[assoc.foreign_key].present?
48
50
  Jason::Subscription.update_ids(
data/lib/jason/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jason
2
- VERSION = "0.6.6"
2
+ VERSION = "0.6.7"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jason-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.6
4
+ version: 0.6.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Rees
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-19 00:00:00.000000000 Z
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - ">="
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sidekiq
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
111
125
  description:
112
126
  email:
113
127
  - jarees@gmail.com
@@ -126,8 +140,9 @@ files:
126
140
  - LICENSE.txt
127
141
  - README.md
128
142
  - Rakefile
129
- - app/controllers/jason/api/pusher_controller.rb
130
- - app/controllers/jason/api_controller.rb
143
+ - app/controllers/jason/jason_controller.rb
144
+ - app/controllers/jason/pusher_controller.rb
145
+ - app/workers/jason/outbound_message_queue_worker.rb
131
146
  - bin/console
132
147
  - bin/setup
133
148
  - client/babel.config.js