effective_messaging 0.7.2 → 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: c36f8cc8cf0b957ff2cd66b902bb3e99cf13673d70da3a086bf837e7b424a6dd
4
- data.tar.gz: 83a47842b7805daa82768dd1457c516b2bdcebd14adbac0000c09f3f4c3af9c7
3
+ metadata.gz: 5daa32cf8a7384da19b824c0dcf5cdea5cf3797e03fbadc420ecf8b99275d3e2
4
+ data.tar.gz: f7bfb3dfefc8a06cb959ecd874e7ae8f4c389b17639496d96637e78b865412bc
5
5
  SHA512:
6
- metadata.gz: 0465d662b13537968d2b36fb6634c308321853290be44ad4763ee5c350fc633a9c45eca56f8f201fb160dcea44b32662ee0d5019dedf7e4511d3c76d82615612
7
- data.tar.gz: de0aee24647a2068e4d8e37f6c72d9e8f90697eb7616d808b174ada792b5e1a12e32bcf7bec2eab52e177187168b86822d752a5554fb6b04f8f0186876ede8dd
6
+ metadata.gz: 99d125bebd71348909a9f60a336778cf0f53e70c1dca482b8a83250348054ea1ab8f6525dd494b05299d39da20756f1bbaa396f811ec20bd3beb4784593370d3
7
+ data.tar.gz: c1debff84d85589cd398fa01d2c0cfcabf8c450a4f05f2986253678df606787f3a3675de60b7b7bdd5040502e73460b3aeb681912dd958d20b38fa74527046df
@@ -278,16 +278,28 @@ module Effective
278
278
 
279
279
  report.collection().find_each do |resource|
280
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
+
281
285
  print('.')
282
286
 
283
- # For logging
284
- assign_attributes(current_resource: resource)
287
+ begin
288
+ # For logging
289
+ assign_attributes(current_resource: resource)
285
290
 
286
- # Send the resource email
287
- build_notification_log(resource: resource).save!
288
- Effective::NotificationsMailer.notify_resource(self, resource).deliver_now
291
+ # Send the resource email
292
+ Effective::NotificationsMailer.notify_resource(self, resource).deliver_now
289
293
 
290
- 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
291
303
 
292
304
  GC.start if (notified % 250) == 0
293
305
  end
@@ -299,9 +311,19 @@ module Effective
299
311
  notified = 0
300
312
 
301
313
  if notifiable_scheduled? || force
302
- build_notification_log(resource: nil).save!
303
- Effective::NotificationsMailer.notify(self).deliver_now
304
- 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
+
305
327
  end
306
328
 
307
329
  notified > 0 ? update!(last_notified_at: Time.zone.now, last_notified_count: notified) : touch
@@ -324,6 +346,17 @@ module Effective
324
346
  notifiable?(resource, date: date)
325
347
  end
326
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
+
327
360
  # Consider the notification logs which track how many and how long ago this notification was sent
328
361
  # It's notifiable? when first time or if it's been immediate_days since last notification
329
362
  def notifiable_immediate?(resource:, date: nil)
@@ -1,3 +1,3 @@
1
1
  module EffectiveMessaging
2
- VERSION = '0.7.2'.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.2
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-11-28 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