smailer 0.7.0 → 0.7.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c72c27e350a0cd53f23e5b4e961f4addceea0fff
4
- data.tar.gz: 6c4fe79f61f4e3ec824d1b6f33d6b9177a9e7ba0
3
+ metadata.gz: 45ce6bb0557460b8103244d490a474e83fe56055
4
+ data.tar.gz: e40b57d41795c0594c368aefc3b6e1ba75e04175
5
5
  SHA512:
6
- metadata.gz: 78a7371b1ec129605f13b0998ad7dc8a41ee462ab077213becdbd88d6bf43e03eda6dd5fdf6ca571e8891a7fc1c5685c0b6393f781b41ef859aee875784dd286
7
- data.tar.gz: 9a9fcd6397f2735e5fd8eb8c5fdb5a7056831c994c69b9b52ec2d06f8162c0a2fe55b777a9c923ba921e98e6e2fb3b5770c6c606e24239f24655f53dba18e137
6
+ metadata.gz: 035cf4b2a412ba828ea8d16321a8a2ea5f82125375c61f1de53fd2b01addafd23db7d5b769daca44407a2a998a5396180df9790872a0cd75157bf6a6f24de428
7
+ data.tar.gz: d8fa22c31c189a8452a16468e1377d3480ea56c79724a78ace3ca313753c1128aa18d96820767bd888236288d25e70bbdac291c23a695eb59c61c80aa600fdfb
@@ -1,19 +1,29 @@
1
1
  module Smailer
2
2
  module Compatibility
3
- def self.rails_3?
3
+ extend self
4
+
5
+ def rails_3?
4
6
  Rails::VERSION::MAJOR == 3
5
7
  end
6
8
 
7
- def self.rails_4?
9
+ def rails_4?
8
10
  Rails::VERSION::MAJOR == 4
9
11
  end
10
12
 
11
- def self.rails_3_or_4?
12
- self.rails_3? || self.rails_4?
13
+ def rails_3_or_4?
14
+ rails_3? || rails_4?
13
15
  end
14
16
 
15
- def self.save_without_validation(object)
17
+ def save_without_validation(object)
16
18
  rails_3_or_4? ? object.save(:validate => false) : object.save(false)
17
19
  end
20
+
21
+ def update_all(scope, fields, conditions)
22
+ if rails_3_or_4?
23
+ scope.where(conditions).update_all(fields)
24
+ else
25
+ scope.update_all(fields, conditions)
26
+ end
27
+ end
18
28
  end
19
29
  end
@@ -29,7 +29,7 @@ module Smailer
29
29
  Compatibility.save_without_validation self if changed?
30
30
  end
31
31
 
32
- def self.add(queued_mail, status = Statuses::SENT)
32
+ def self.add(queued_mail, status = Statuses::SENT, update_sent_mails_count = true)
33
33
  finished = self.new
34
34
 
35
35
  fields_to_copy = [:mail_campaign_id, :key, :from, :to, :subject, :retries, :last_retry_at, :last_error]
@@ -45,7 +45,7 @@ module Smailer
45
45
  finished.save!
46
46
  queued_mail.destroy
47
47
 
48
- if finished.mail_campaign
48
+ if update_sent_mails_count && finished.mail_campaign
49
49
  finished.mail_campaign.sent_mails_count += 1
50
50
  Compatibility.save_without_validation finished.mail_campaign
51
51
  end
@@ -30,11 +30,7 @@ module Smailer
30
30
 
31
31
  # clean up any old locked items
32
32
  expired_locks_condition = ['locked = ? AND locked_at <= ?', true, 1.hour.ago.utc]
33
- if Smailer::Compatibility.rails_3_or_4?
34
- Smailer::Models::QueuedMail.where(expired_locks_condition).update_all(:locked => false)
35
- else
36
- Smailer::Models::QueuedMail.update_all({:locked => false}, expired_locks_condition)
37
- end
33
+ Smailer::Compatibility.update_all(Smailer::Models::QueuedMail, {:locked => false}, expired_locks_condition)
38
34
 
39
35
  # load the queue items to process
40
36
  queue_sort_order = 'retries ASC, id ASC'
@@ -47,15 +43,12 @@ module Smailer
47
43
  # lock the queue items
48
44
  lock_condition = {:id => items_to_process.map(&:id)}
49
45
  lock_update = {:locked => true, :locked_at => Time.now.utc}
50
- if Smailer::Compatibility.rails_3_or_4?
51
- Smailer::Models::QueuedMail.where(lock_condition).update_all(lock_update)
52
- else
53
- Smailer::Models::QueuedMail.update_all(lock_update, lock_condition)
54
- end
46
+ Smailer::Compatibility.update_all(Smailer::Models::QueuedMail, lock_update, lock_condition)
55
47
 
56
48
  # map of attachment ID to contents - so we don't keep opening files
57
49
  # or URLs
58
50
  cached_attachments = {}
51
+ finished_mails_counts = Hash.new(0)
59
52
 
60
53
  items_to_process.each do |queue_item|
61
54
  # try to send the email
@@ -107,16 +100,22 @@ module Smailer
107
100
 
108
101
  if retries_exceeded || too_old
109
102
  # the message has expired; move to finished_mails
110
- Smailer::Models::FinishedMail.add(queue_item, Smailer::Models::FinishedMail::Statuses::FAILED)
103
+ Smailer::Models::FinishedMail.add(queue_item, Smailer::Models::FinishedMail::Statuses::FAILED, false)
104
+ finished_mails_counts[queue_item.mail_campaign.id] += 1
111
105
  end
112
106
  results.push [queue_item, :failed]
113
107
  else
114
108
  # great job, message sent
115
- Smailer::Models::FinishedMail.add(queue_item, Smailer::Models::FinishedMail::Statuses::SENT)
109
+ Smailer::Models::FinishedMail.add(queue_item, Smailer::Models::FinishedMail::Statuses::SENT, false)
110
+ finished_mails_counts[queue_item.mail_campaign.id] += 1
116
111
  results.push [queue_item, :sent]
117
112
  end
118
113
  end
119
114
 
115
+ finished_mails_counts.each do |mail_campaign_id, finished_mails_for_campaign|
116
+ Smailer::Models::MailCampaign.update_counters mail_campaign_id, :sent_mails_count => finished_mails_for_campaign
117
+ end
118
+
120
119
  results
121
120
  end
122
121
  end
@@ -1,7 +1,7 @@
1
1
  module Smailer
2
2
  MAJOR = 0
3
3
  MINOR = 7
4
- PATCH = 0
4
+ PATCH = 1
5
5
 
6
6
  VERSION = [MAJOR, MINOR, PATCH].join('.')
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smailer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dimitar Dimitrov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-23 00:00:00.000000000 Z
11
+ date: 2014-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
106
  version: 1.3.6
107
107
  requirements: []
108
108
  rubyforge_project: smailer
109
- rubygems_version: 2.2.0
109
+ rubygems_version: 2.2.2
110
110
  signing_key:
111
111
  specification_version: 4
112
112
  summary: A simple newsletter mailer for Rails.