effective_messaging 0.7.1 → 0.7.3
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/app/models/effective/notification.rb +49 -11
- data/lib/effective_messaging/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5daa32cf8a7384da19b824c0dcf5cdea5cf3797e03fbadc420ecf8b99275d3e2
|
4
|
+
data.tar.gz: f7bfb3dfefc8a06cb959ecd874e7ae8f4c389b17639496d96637e78b865412bc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 99d125bebd71348909a9f60a336778cf0f53e70c1dca482b8a83250348054ea1ab8f6525dd494b05299d39da20756f1bbaa396f811ec20bd3beb4784593370d3
|
7
|
+
data.tar.gz: c1debff84d85589cd398fa01d2c0cfcabf8c450a4f05f2986253678df606787f3a3675de60b7b7bdd5040502e73460b3aeb681912dd958d20b38fa74527046df
|
@@ -73,8 +73,13 @@ module Effective
|
|
73
73
|
timestamps
|
74
74
|
end
|
75
75
|
|
76
|
-
|
77
|
-
|
76
|
+
if EffectiveResources.serialize_with_coder?
|
77
|
+
serialize :audience_emails, type: Array, coder: YAML
|
78
|
+
serialize :scheduled_dates, type: Array, coder: YAML
|
79
|
+
else
|
80
|
+
serialize :audience_emails, Array
|
81
|
+
serialize :scheduled_dates, Array
|
82
|
+
end
|
78
83
|
|
79
84
|
scope :sorted, -> { order(:id) }
|
80
85
|
scope :deep, -> { includes(report: :report_columns) }
|
@@ -273,16 +278,28 @@ module Effective
|
|
273
278
|
|
274
279
|
report.collection().find_each do |resource|
|
275
280
|
next unless notifiable?(resource) || force
|
281
|
+
|
282
|
+
# Send Now functionality. Don't duplicate if it's same day.
|
283
|
+
next if force && already_notified_today?(resource)
|
284
|
+
|
276
285
|
print('.')
|
277
286
|
|
278
|
-
|
279
|
-
|
287
|
+
begin
|
288
|
+
# For logging
|
289
|
+
assign_attributes(current_resource: resource)
|
280
290
|
|
281
|
-
|
282
|
-
|
283
|
-
Effective::NotificationsMailer.notify_resource(self, resource).deliver_now
|
291
|
+
# Send the resource email
|
292
|
+
Effective::NotificationsMailer.notify_resource(self, resource).deliver_now
|
284
293
|
|
285
|
-
|
294
|
+
# Log that it was sent
|
295
|
+
build_notification_log(resource: resource).save!
|
296
|
+
|
297
|
+
# Count how many we actually sent
|
298
|
+
notified += 1
|
299
|
+
rescue => e
|
300
|
+
EffectiveLogger.error(e.message, associated: self) if defined?(EffectiveLogger)
|
301
|
+
ExceptionNotifier.notify_exception(e, data: { notification_id: id, resource_id: resource.id, resource_type: resource.class.name }) if defined?(ExceptionNotifier)
|
302
|
+
end
|
286
303
|
|
287
304
|
GC.start if (notified % 250) == 0
|
288
305
|
end
|
@@ -294,9 +311,19 @@ module Effective
|
|
294
311
|
notified = 0
|
295
312
|
|
296
313
|
if notifiable_scheduled? || force
|
297
|
-
|
298
|
-
|
299
|
-
|
314
|
+
begin
|
315
|
+
Effective::NotificationsMailer.notify(self).deliver_now
|
316
|
+
|
317
|
+
# Log that it was sent
|
318
|
+
build_notification_log(resource: nil).save!
|
319
|
+
|
320
|
+
# Count how many we actually sent
|
321
|
+
notified += 1
|
322
|
+
rescue => e
|
323
|
+
EffectiveLogger.error(e.message, associated: self) if defined?(EffectiveLogger)
|
324
|
+
ExceptionNotifier.notify_exception(e, data: { notification_id: id }) if defined?(ExceptionNotifier)
|
325
|
+
end
|
326
|
+
|
300
327
|
end
|
301
328
|
|
302
329
|
notified > 0 ? update!(last_notified_at: Time.zone.now, last_notified_count: notified) : touch
|
@@ -319,6 +346,17 @@ module Effective
|
|
319
346
|
notifiable?(resource, date: date)
|
320
347
|
end
|
321
348
|
|
349
|
+
def already_notified_today?(resource)
|
350
|
+
email = resource_email(resource) || resource_user(resource).try(:email)
|
351
|
+
raise("expected an email for #{report} #{report&.id} and #{resource} #{resource&.id}") unless email.present?
|
352
|
+
|
353
|
+
logs = notification_logs.select { |log| log.email == email }
|
354
|
+
return false if logs.count == 0
|
355
|
+
|
356
|
+
# If we already notified today
|
357
|
+
logs.any? { |log| log.created_at&.beginning_of_day == Time.zone.now.beginning_of_day }
|
358
|
+
end
|
359
|
+
|
322
360
|
# Consider the notification logs which track how many and how long ago this notification was sent
|
323
361
|
# It's notifiable? when first time or if it's been immediate_days since last notification
|
324
362
|
def notifiable_immediate?(resource:, date: nil)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_messaging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|