hyper-resource 1.0.0.lap65 → 1.0.0.lap66
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/hyperloop/resource/pub_sub.rb +65 -0
- data/lib/hyperloop/resource/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ee8eab3b7eff49cb5b3a0f06043eaf33d6f7f57dc30ac4eac1b93aee10eaf02
|
4
|
+
data.tar.gz: 429255faceed5e914c021d0cdff236ec15d916ef80af987ce0f8ffc9623696c5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b05ab3c365aca997b5f620ecdb6de504125cfbdcd9e3e0aa77b1079e1e78b76a518d1bda91c99fa4b8a2b6f44436f348999f5bdff1e351fd5b07ded60041a9ab
|
7
|
+
data.tar.gz: 3346b0e834f534cbd7beea750134dc4fa27adb92a0ac0b3819800288ae4a65daf5e674a6dcac3e0aeffab408d4200dc0cf0ec8bf866cf8c6794b44afacb1c5b5
|
@@ -71,6 +71,45 @@ module Hyperloop
|
|
71
71
|
Hyperloop.redis_instance.del("HRPS__#{record.class}__#{record.id}") if record.destroyed?
|
72
72
|
end
|
73
73
|
|
74
|
+
def publish_rest_class_method(record_class, rest_class_method_name)
|
75
|
+
subscribers = Hyperloop.redis_instance.hgetall("HRPS__#{record_class}__rest_class_method__#{rest_class_method_name}")
|
76
|
+
time_now = Time.now.to_f
|
77
|
+
scrub_time = time_now - 24.hours.to_f
|
78
|
+
subscribers.each do |session_id, last_requested|
|
79
|
+
if last_requested.to_f < scrub_time
|
80
|
+
Hyperloop.redis_instance.hdel("HRPS__#{record_class}__rest_class_method__#{rest_class_method_name}", session_id)
|
81
|
+
next
|
82
|
+
end
|
83
|
+
message = {
|
84
|
+
record_type: record_class.to_s,
|
85
|
+
rest_class_method: rest_class_method_name
|
86
|
+
}
|
87
|
+
if Hyperloop.resource_transport == :pusher
|
88
|
+
_pusher_client.trigger("hyper-record-update-channel-#{session_id}", 'update', message)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def publish_rest_method(record, method_name)
|
94
|
+
subscribers = Hyperloop.redis_instance.hgetall("HRPS__#{record.class}__#{record.id}__rest_method__#{method_name}")
|
95
|
+
time_now = Time.now.to_f
|
96
|
+
scrub_time = time_now - 24.hours.to_f
|
97
|
+
subscribers.each do |session_id, last_requested|
|
98
|
+
if last_requested.to_f < scrub_time
|
99
|
+
Hyperloop.redis_instance.hdel("HRPS__#{record.class}__#{record.id}__rest_method__#{method_name}", session_id)
|
100
|
+
next
|
101
|
+
end
|
102
|
+
message = {
|
103
|
+
record_type: record_class.to_s,
|
104
|
+
id: record.id,
|
105
|
+
rest_method: method_name
|
106
|
+
}
|
107
|
+
if Hyperloop.resource_transport == :pusher
|
108
|
+
_pusher_client.trigger("hyper-record-update-channel-#{session_id}", 'update', message)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
74
113
|
def publish_scope(record_class, scope_name)
|
75
114
|
subscribers = Hyperloop.redis_instance.hgetall("HRPS__#{record_class}__scope__#{scope_name}")
|
76
115
|
time_now = Time.now.to_f
|
@@ -113,6 +152,22 @@ module Hyperloop
|
|
113
152
|
Hyperloop.redis_instance.hset "HRPS__#{record.class}__#{record.id}", session.id.to_s, Time.now.to_f.to_s
|
114
153
|
end
|
115
154
|
|
155
|
+
def subscribe_rest_class_method(record_class, rest_class_method_name)
|
156
|
+
return unless session.id
|
157
|
+
time_now = Time.now.to_f.to_s
|
158
|
+
session_id = session.id.to_s
|
159
|
+
Hyperloop.redis_instance.pipelined do
|
160
|
+
Hyperloop.redis_instance.hset("HRPS__#{record_class}__rest_class_method_name__#{rest_class_method_name}", session_id, time_now)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
def subscribe_rest_method(record, rest_method_name)
|
165
|
+
return unless session.id
|
166
|
+
time_now = Time.now.to_f.to_s
|
167
|
+
session_id = session.id.to_s
|
168
|
+
Hyperloop.redis_instance.hset("HRPS__#{record.class}__#{record.id}__rest_method__#{rest_method_name}", session_id, time_now)
|
169
|
+
end
|
170
|
+
|
116
171
|
def subscribe_scope(collection, record_class = nil, scope_name = nil)
|
117
172
|
return unless session.id
|
118
173
|
time_now = Time.now.to_f.to_s
|
@@ -137,6 +192,16 @@ module Hyperloop
|
|
137
192
|
publish_record(record)
|
138
193
|
end
|
139
194
|
|
195
|
+
def pub_sub_rest_class_method(record_class, rest_class_method_name)
|
196
|
+
subscribe_rest_class_method(record_class, rest_class_method_name)
|
197
|
+
publish_rest_class_method(record_class, rest_class_method_name)
|
198
|
+
end
|
199
|
+
|
200
|
+
def pub_sub_rest_method(record, rest_method_name)
|
201
|
+
subscribe_rest_method(record, rest_method_name)
|
202
|
+
publish_rest_method(record, rest_method_name)
|
203
|
+
end
|
204
|
+
|
140
205
|
def pub_sub_scope(collection, record_class, scope_name)
|
141
206
|
subscribe_scope(collection, record_class, scope_name)
|
142
207
|
publish_scope(record_class, scope_name)
|