postburner 0.6.0 → 0.6.1

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: f0c2a65b18596dafa8809d07924e2274f7adc05ce971fea1b82143c7132f2929
4
- data.tar.gz: e3000b8fa490aec4fb1c8b49c54fe7ee78613b3e7e3849c2270d7a7dd01adecd
3
+ metadata.gz: ca9bed4afd8b585d14934b4ba09b20c58109d8de39d5300d135069e2723c3aba
4
+ data.tar.gz: 5ae5f4a07e53ac69b4d4b795f3b8c8bdf5b9a087e1a8513f6fed03cb47e48210
5
5
  SHA512:
6
- metadata.gz: 87cb7aec3924346ab43b93f5886aebfb1b138a36b199eb3e10032404a23b07774c287cb96ed8c4889feabde1106aba63d23d6429cead43f3eec8211f257d6baa
7
- data.tar.gz: 94e32291c4f00db869a630adeea7e44abb92c4938e2314fc5e46ea487b874acc4a74b80771bd8db8944f3a7c98e06101ef90a36f8da5bf72d7fecc82fbd14c3c
6
+ metadata.gz: c741884d62b1b71b7c8ce928baff5fef35054c58962f530ee06764b4947477ca394712300256e98409187494092c7164a5f8490482e54a19d0f1776b8465f783
7
+ data.tar.gz: 193a2e625139d0a441503afc15d64888eb25234d0ae81ca320a319506130e8eb1c960141d60b97066633f6a777ab47fe21d49d42bc448497b4225e8c78924051
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## v0.6.1 - 2021-11-01
4
+
5
+ ### Updated
6
+ - update run_at logic to support only inserting after save commit.
7
+
3
8
  ## v0.6.0 - 2021-11-01
4
9
 
5
10
  ### Added
@@ -24,25 +24,31 @@ module Postburner
24
24
 
25
25
  before_validation :ensure_sid!
26
26
  before_destroy :delete!
27
+ after_save_commit :insert_if_queued!
27
28
 
28
29
  validates :sid, presence: {strict: true}
29
30
 
30
31
  def queue!(options={})
31
32
  return if self.queued_at.present? && self.bkid.present?
33
+ raise ActiveRecord::RecordInvalid, "Can't queue unless valid." unless self.valid?
34
+ at = options.delete(:at)
32
35
 
33
- self.save!
36
+ self.run_at = case
37
+ when at.present?
38
+ # this is rudimentary, add error handling
39
+ options[:delay] ||= at.to_i - Time.zone.now.to_i
40
+ at
41
+ when options[:delay].present?
42
+ Time.zone.now + options[:delay].seconds
43
+ end
34
44
 
35
- case
36
- when options[:at].present?
37
- # this is rudimentary, add error handling
38
- options[:delay] ||= options[:at].to_i - Time.zone.now.to_i
39
- update_column :run_at, options[:at]
40
- options.delete(:at)
41
- when options[:delay].present?
42
- update_column :run_at, Time.zone.now + options[:delay].seconds
43
- end
45
+ @_insert_options = options
46
+
47
+ self.save!
48
+ end
44
49
 
45
- insert!(options)
50
+ def will_insert?
51
+ @_insert_options.is_a? Hash
46
52
  end
47
53
 
48
54
  # tube: backburner.worker.queue.backburner-jobs
@@ -224,6 +230,10 @@ module Postburner
224
230
  }.merge(data))
225
231
  end
226
232
 
233
+ def insert_if_queued!
234
+ return unless self.will_insert?
235
+ insert!(@_insert_options)
236
+ end
227
237
 
228
238
  def insert!(options={})
229
239
  response = Backburner::Worker.enqueue(
@@ -1,3 +1,3 @@
1
1
  module Postburner
2
- VERSION = '0.6.0'
2
+ VERSION = '0.6.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postburner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Smith