inst-jobs 0.15.18 → 0.15.19

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: 1f5fa07aabb776db7b07347664cd263fae34426050ea23b72e2f35ef6a665f46
4
- data.tar.gz: cfb860844d1a2c3654a8047f8c32331fab957f6fd1d5ac77f641f2704849d738
3
+ metadata.gz: 988fd063fdecd8a94025cf8b9d1db853e3397ab3842942928cbdc99e241d0d80
4
+ data.tar.gz: c20258789ad05909efe3125e70a34bceb2a124398e43dbdf7d4b3c3d6dadf8ab
5
5
  SHA512:
6
- metadata.gz: 9dd503fd8af0128fc999a78f96b199f759ea1c9df121f816ee72dd288d2e6bc6480b69bdece15f8f32c167e9785d18d9fb4b262abfd8459e08c12771d3dbe606
7
- data.tar.gz: cb4f63db74b2cd05fde625c43e100c07cd66ded4f3b0998d97bb19786befde179180b85b1dd45d193254bdd010aba9e2ddaf67b549d0e8cdc0657853b99146ed
6
+ metadata.gz: e5f688d3413484f51c93270aea753178915ed38cdd3081dba5816621b070a99cea9c5bd518757db43ced1607a651241f8cd62f5160f5ea53cf113a7df3cab8c7
7
+ data.tar.gz: fb563b85cc6b7caaef52e63342f00ce06ad0d30c75a3adaa47b7f8e81565a77610e4c3fc7aea7b3af1c703ea9e5f5e80c8801cf7ec4dc0cd10569cae57ebfcde
@@ -27,42 +27,54 @@ module Delayed
27
27
 
28
28
  # modified from ActiveRecord::Persistence.create and ActiveRecord::Persistence#_insert_record
29
29
  job = new(attributes, &block)
30
- # a before_save callback that we're skipping
31
- job.initialize_defaults
30
+ job.single_step_create
31
+ end
32
+ end
32
33
 
33
- current_time = current_time_from_proper_timezone
34
+ def single_step_create
35
+ connection = self.class.connection
36
+ return save if connection.prepared_statements || Rails.version < '5.2'
34
37
 
35
- job.send(:all_timestamp_attributes_in_model).each do |column|
36
- if !job.attribute_present?(column)
37
- job._write_attribute(column, current_time)
38
- end
39
- end
38
+ # a before_save callback that we're skipping
39
+ initialize_defaults
40
40
 
41
- if Rails.version >= '6'
42
- attribute_names = job.send(:attribute_names_for_partial_writes)
43
- attribute_names = job.send(:attributes_for_create, attribute_names)
44
- values = job.send(:attributes_with_values, attribute_names)
45
- else
46
- attribute_names = job.partial_writes? ? job.send(:keys_for_partial_write) : self.attribute_names
47
- values = job.send(:attributes_with_values_for_create, attribute_names)
41
+ current_time = current_time_from_proper_timezone
42
+
43
+ all_timestamp_attributes_in_model.each do |column|
44
+ if !attribute_present?(column)
45
+ _write_attribute(column, current_time)
48
46
  end
49
- im = arel_table.compile_insert(_substitute_values(values))
50
- sql, _binds = connection.send(:to_sql_and_binds, im, [])
51
-
52
- # https://www.postgresql.org/docs/9.5/libpq-exec.html
53
- sql = "#{sql} RETURNING id"
54
- # > Multiple queries sent in a single PQexec call are processed in a single transaction,
55
- # unless there are explicit BEGIN/COMMIT commands included in the query string to divide
56
- # it into multiple transactions.
57
- sql = "SELECT pg_advisory_xact_lock(#{connection.quote_table_name('half_md5_as_bigint')}(#{connection.quote(values['strand'])})); #{sql}" if values["strand"]
58
- result = connection.execute(sql, "#{self} Create")
59
- job.id = result.values.first.first
60
- result.clear
61
- job.instance_variable_set(:@new_record, false)
62
- job.changes_applied
63
-
64
- job
65
47
  end
48
+
49
+ if Rails.version >= '6'
50
+ attribute_names = attribute_names_for_partial_writes
51
+ attribute_names = attributes_for_create(attribute_names)
52
+ values = attributes_with_values(attribute_names)
53
+ else
54
+ attribute_names = partial_writes? ? keys_for_partial_write : self.attribute_names
55
+ values = attributes_with_values_for_create(attribute_names)
56
+ end
57
+ im = self.class.arel_table.compile_insert(self.class.send(:_substitute_values, values))
58
+ sql, _binds = connection.send(:to_sql_and_binds, im, [])
59
+
60
+ # https://www.postgresql.org/docs/9.5/libpq-exec.html
61
+ sql = "#{sql} RETURNING id"
62
+ # > Multiple queries sent in a single PQexec call are processed in a single transaction,
63
+ # unless there are explicit BEGIN/COMMIT commands included in the query string to divide
64
+ # it into multiple transactions.
65
+ sql = "SELECT pg_advisory_xact_lock(#{connection.quote_table_name('half_md5_as_bigint')}(#{connection.quote(values['strand'])})); #{sql}" if values["strand"]
66
+ result = connection.execute(sql, "#{self} Create")
67
+ self.id = result.values.first.first
68
+ result.clear
69
+ @new_record = false
70
+ changes_applied
71
+
72
+ self
73
+ end
74
+
75
+ def destroy
76
+ # skip transaction and callbacks
77
+ destroy_row
66
78
  end
67
79
 
68
80
  # be aware that some strand functionality is controlled by triggers on
@@ -464,7 +476,7 @@ module Delayed
464
476
  raise "job already exists" unless new_record?
465
477
  self.locked_at = Delayed::Job.db_time_now
466
478
  self.locked_by = worker
467
- save!
479
+ single_step_create
468
480
  end
469
481
 
470
482
  def fail!
@@ -1,3 +1,3 @@
1
1
  module Delayed
2
- VERSION = "0.15.18"
2
+ VERSION = "0.15.19"
3
3
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ../..
3
3
  specs:
4
- inst-jobs (0.15.15)
4
+ inst-jobs (0.15.18)
5
5
  activerecord (>= 4.2)
6
6
  activesupport (>= 4.2)
7
7
  after_transaction_commit (>= 1.0, < 3)
@@ -65,9 +65,9 @@ GEM
65
65
  database_cleaner (1.6.1)
66
66
  diff-lcs (1.3)
67
67
  erubi (1.7.1)
68
- et-orbi (1.2.2)
68
+ et-orbi (1.2.4)
69
69
  tzinfo
70
- fugit (1.3.3)
70
+ fugit (1.3.4)
71
71
  et-orbi (~> 1.1, >= 1.1.8)
72
72
  raabro (~> 1.1)
73
73
  globalid (0.4.1)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.15.18
4
+ version: 0.15.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Luetke
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2020-04-02 00:00:00.000000000 Z
12
+ date: 2020-04-13 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord