effective_messaging 0.7.1 → 0.7.3

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: 5ba14b4ea2b24940ece309555b7879f4d94ea043579c2c742ab7a06a962dbc6f
4
- data.tar.gz: 42a326bea211a01340dc3128476170107aba231634ea9d133f77b913e8e9be1c
3
+ metadata.gz: 5daa32cf8a7384da19b824c0dcf5cdea5cf3797e03fbadc420ecf8b99275d3e2
4
+ data.tar.gz: f7bfb3dfefc8a06cb959ecd874e7ae8f4c389b17639496d96637e78b865412bc
5
5
  SHA512:
6
- metadata.gz: b8dc9a1d4c7324144721c38380bb8fb728a375e50bf7cc02dfc5ed40b87e8f392e6967ddf61186bf13d88a69a1bd888ef61ca95f3a0c82144fdcd9de440a24a4
7
- data.tar.gz: 5dbbea251f9d27a09b453ff2d6be8b09676675190e7a04f50010afe684ca0eaef0ad7f05c65855c43dea39ffe99f6329e9f10cf4a8cca8d20da910f5ca2bbbf2
6
+ metadata.gz: 99d125bebd71348909a9f60a336778cf0f53e70c1dca482b8a83250348054ea1ab8f6525dd494b05299d39da20756f1bbaa396f811ec20bd3beb4784593370d3
7
+ data.tar.gz: c1debff84d85589cd398fa01d2c0cfcabf8c450a4f05f2986253678df606787f3a3675de60b7b7bdd5040502e73460b3aeb681912dd958d20b38fa74527046df
@@ -73,8 +73,13 @@ module Effective
73
73
  timestamps
74
74
  end
75
75
 
76
- serialize :audience_emails, Array
77
- serialize :scheduled_dates, Array
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
- # For logging
279
- assign_attributes(current_resource: resource)
287
+ begin
288
+ # For logging
289
+ assign_attributes(current_resource: resource)
280
290
 
281
- # Send the resource email
282
- build_notification_log(resource: resource).save!
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
- notified += 1
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
- build_notification_log(resource: nil).save!
298
- Effective::NotificationsMailer.notify(self).deliver_now
299
- notified += 1
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)
@@ -1,3 +1,3 @@
1
1
  module EffectiveMessaging
2
- VERSION = '0.7.1'.freeze
2
+ VERSION = '0.7.3'.freeze
3
3
  end
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.1
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: 2023-10-26 00:00:00.000000000 Z
11
+ date: 2024-02-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails