foreign_office 0.16.6 → 0.17.0

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: 605ceee6b8967fa3a87fede021e512e87e8b65a5eb5fe32622e1c481c5ce5174
4
- data.tar.gz: 649a6521d4aa91f6e314eba632d8d4ac2254c5d4d547a27c387cfac468b9996e
3
+ metadata.gz: 9d0c9446d27d1d583ef264ee14cf028f1ecc84a82d9fa7a300889205e4bcbfd6
4
+ data.tar.gz: b64b5d31d96a7d85d22138078a2205305df5cc1458d62610bd68f9d82fcfa990
5
5
  SHA512:
6
- metadata.gz: f385241ee4b86e6414cbca7414463b772a3e9c4d5005670903980a00068a0909c517f0b153d1bfdcf44ba95167182bcbb55e44526393c9c61b8ce030723e312f
7
- data.tar.gz: 3e716c0c8eab1fe8dc4fc9badafa6e417bf5313f2aa32f09c97a1b7cf66a655c3b1148c602e6141717e6413d3b1b38b1fcfbf5310296721babd1b6873a2f09a8
6
+ metadata.gz: 2d5c3db38421294c670162bd9d98cdeb43e2f52d89de1a38cf70bce84aaca81e680e076e409594544d79c856611875c22826e8e6d7bda248c4afc38d2de8283a
7
+ data.tar.gz: e79c2b10c802e27b7feeb382dcbefd43d9abff92bda3456cc628930f6b84c26d320748c7e481f6679c69154607dc92a77ee6ee825819429419991354625ce7cb
@@ -0,0 +1,32 @@
1
+ class PresenceChannelPublishJob < ApplicationJob
2
+ queue_as :default
3
+
4
+ def perform(obj_id, obj_class_name, serialized_state)
5
+ serialized_state.symbolize_keys!
6
+ channel_name = "presence-#{obj_class_name}#{obj_id}"
7
+ channel_presence = ForeignOffice.bus.connection.channel_users(channel_name)
8
+ if channel_presence[:users].any?
9
+ ForeignOffice.publish(
10
+ channel: channel_name,
11
+ object: serialized_state
12
+ )
13
+ else
14
+ serialized_state[:foreign_office_retries] ||= 0
15
+ if serialized_state[:foreign_office_retries] < 4 # four total tries
16
+ retry_wait = 2**serialized_state[:foreign_office_retries]
17
+ serialized_state[:foreign_office_retries] += 1
18
+ PresenceChannelPublishJob.set(wait: retry_wait).perform_later(obj_id, obj_class_name, serialized_state)
19
+ else
20
+ failure_message = "PresenceChannelPublishJob: client never connected, not able to send"
21
+ dont_raise = StandardError.new(failure_message)
22
+ Bugsnag.notify(dont_raise) do |report|
23
+ report.severity = 'error'
24
+ report.add_tab(:presence_channel, obj_class_name: obj_class_name, obj_id: obj_id, serialized_state: serialized_state)
25
+ end
26
+ Rails.logger.error(failure_message)
27
+ Rails.logger.error("PresenceChannelPublishJob: #{obj_class_name}: #{obj_id}: #{serialized_state}")
28
+ end
29
+ end
30
+ end
31
+
32
+ end
@@ -9,10 +9,12 @@ module ForeignOffice
9
9
 
10
10
  def broadcast_change
11
11
  Rails.logger.debug "Broadcasting change for #{self.inspect}..."
12
- Rails.logger.debug "Class name: #{self.class.name}"
13
- Rails.logger.debug "ID: #{self.id}"
14
12
  Rails.logger.debug "Serialize: #{self.serialize}"
15
- ForeignOffice.publish(channel: "#{self.class.name}#{self.id}", object: self.serialize)
13
+ if self.class.channel_presence_required?
14
+ PresenceChannelPublishJob.set(wait: 1).perform_later(id, self.class.name, self.serialize)
15
+ else
16
+ ForeignOffice.publish(channel: "#{self.class.name}#{self.id}", object: self.serialize)
17
+ end
16
18
  rescue => e
17
19
  Rails.logger.error "Failed to broadcast change: #{e.inspect}"
18
20
  Rails.logger.debug e.backtrace.join("\n")
@@ -28,6 +30,15 @@ module ForeignOffice
28
30
  def broadcast_changes!
29
31
  self.send(:after_save, :handle_broadcast, {unless: :skip_all_callbacks})
30
32
  end
33
+
34
+ def require_channel_presence
35
+ @channel_presence_required = true
36
+ end
37
+
38
+ def channel_presence_required?
39
+ @channel_presence_required
40
+ end
31
41
  end
42
+
32
43
  end
33
- end
44
+ end
@@ -2,8 +2,9 @@ module ForeignOffice
2
2
  module ForeignOfficeHelper
3
3
  def listener_attrs(resource, key, reveal_hide: false, endpoint: nil, download: nil,
4
4
  trigger: nil, delete: nil, href_target: nil, create_modal: nil, mask_me: nil,
5
- exclude_value: nil, browser_tab_id: nil )
6
- channel = "#{resource.class.name}#{resource.id}"
5
+ exclude_value: nil, browser_tab_id: nil, presence: false )
6
+ presence_prefix = presence ? 'presence-' : ''
7
+ channel = "#{presence_prefix}#{resource.class.name}#{resource.id}"
7
8
  channel += "@#{browser_tab_id}" if browser_tab_id
8
9
  data_attrs = "data-listener=true data-channel=#{channel}"
9
10
  if delete
@@ -50,8 +51,9 @@ module ForeignOffice
50
51
 
51
52
  def listener_hash(resource, key, reveal_hide: false, endpoint: nil, download: nil,
52
53
  trigger: nil, delete: nil, href_target: nil, create_modal: nil, mask_me: nil,
53
- exclude_value: nil, browser_tab_id: nil)
54
- channel = "#{resource.class.name}#{resource.id}"
54
+ exclude_value: nil, browser_tab_id: nil, presence: false)
55
+ presence_prefix = presence ? 'presence-' : ''
56
+ channel = "#{presence_prefix}#{resource.class.name}#{resource.id}"
55
57
  channel += "@#{browser_tab_id}" if browser_tab_id
56
58
  hash = {listener: true, channel: channel}
57
59
  if delete
@@ -1,3 +1,3 @@
1
1
  module ForeignOffice
2
- VERSION = "0.16.6"
2
+ VERSION = "0.17.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreign_office
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.6
4
+ version: 0.17.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric Draut
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2018-10-08 00:00:00.000000000 Z
12
+ date: 2018-10-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -89,6 +89,7 @@ files:
89
89
  - app/assets/javascripts/pubnub_bus.js
90
90
  - app/assets/javascripts/pusher_bus.js
91
91
  - app/assets/javascripts/test_bus.js
92
+ - app/jobs/presence_channel_publish_job.rb
92
93
  - lib/foreign_office.rb
93
94
  - lib/foreign_office/broadcaster.rb
94
95
  - lib/foreign_office/busses/generic_bus.rb