crono_trigger 0.6.2 → 0.6.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: 50a79e41f2762ce69d2667b8f9af205a30764986f8f7dab39c6ad26539e35e5d
4
- data.tar.gz: 8d10f131f42691ee9e8b4f0479f8959d9ac7f8b3ff3b5e33b03d10c5933d49a0
3
+ metadata.gz: e08f955458cc12b3cd3f3aab84e0f662d760c7a72872c655708e70aa4d4d0ac3
4
+ data.tar.gz: de4c5fdd13008080291d3adf542e05a9fb5e233f423a8d83ea8bc0bc70a09cde
5
5
  SHA512:
6
- metadata.gz: bf08091433a57d26df8e5fc92098e9e9b19a2693394c7006f60cfb86202f3856d848c2781eb1164436e47ba98ac9bb9e07319ca508092668f94b390735f28fdb
7
- data.tar.gz: 6d5cba81e1169e57258fbd410aeaf5ab27a12155c93ad4ca7ec1b64b1fce6f7eca9b0fa57aa0dbaa9bcfa68118c67e0fe0dc64b16e9541cbd6ffb7b36b78012f
6
+ metadata.gz: ff4f9d234a111fe0d6815e8d6e4d60a003bfc1891a299b808ac89bfc62ef05f4f0146b770ea924c5a7c592852bfb613053ea41ae51344fcc86c2ed4b00c0ea6f
7
+ data.tar.gz: eed66811d98184c25ecaa8c8fcecc9a44b4dcf46f8cff4bd469af2131ce948c9eca1f0dfa3185d6e3f42f1411322934d74ba666daa0b014d2092cff0cb46a0c1
@@ -5,6 +5,9 @@ module CronoTrigger
5
5
  @stop_flag = stop_flag
6
6
  @logger = logger
7
7
  @executor = executor
8
+ if @executor.fallback_policy != :caller_runs
9
+ raise ArgumentError, "executor's fallback policies except for :caller_runs are not supported"
10
+ end
8
11
  @execution_counter = execution_counter
9
12
  @quiet = Concurrent::AtomicBoolean.new(false)
10
13
  end
@@ -50,34 +53,28 @@ module CronoTrigger
50
53
  end
51
54
 
52
55
  def poll(model)
53
- @logger.debug "(polling-thread-#{Thread.current.object_id}) Poll #{model}"
54
- records = []
55
- overflowed_record_ids = []
56
+ @logger.info "(polling-thread-#{Thread.current.object_id}) Poll #{model}"
56
57
 
57
- begin
58
- model.connection_pool.with_connection do
59
- records = model.executables_with_lock
58
+ maybe_has_next = true
59
+ while maybe_has_next
60
+ records, maybe_has_next = model.connection_pool.with_connection do
61
+ model.executables_with_lock
60
62
  end
61
63
 
62
64
  records.each do |record|
63
- begin
64
- @executor.post do
65
- @execution_counter.increment
66
- begin
67
- process_record(record)
68
- ensure
69
- @execution_counter.decrement
70
- end
65
+ @executor.post do
66
+ @execution_counter.increment
67
+ begin
68
+ process_record(record)
69
+ ensure
70
+ @execution_counter.decrement
71
71
  end
72
- rescue Concurrent::RejectedExecutionError
73
- overflowed_record_ids << record.id
74
72
  end
75
73
  end
76
- unlock_overflowed_records(model, overflowed_record_ids)
77
- end while overflowed_record_ids.empty? && records.any?
74
+ end
78
75
  end
79
76
 
80
- private
77
+ private
81
78
 
82
79
  def process_record(record)
83
80
  record.class.connection_pool.with_connection do
@@ -88,16 +85,5 @@ module CronoTrigger
88
85
  @logger.error(ex)
89
86
  CronoTrigger::GlobalExceptionHandler.handle_global_exception(ex)
90
87
  end
91
-
92
- def unlock_overflowed_records(model, overflowed_record_ids)
93
- model.connection_pool.with_connection do
94
- unless overflowed_record_ids.empty?
95
- model.where(id: overflowed_record_ids).crono_trigger_unlock_all!
96
- end
97
- end
98
- rescue ActiveRecord::ConnectionNotEstablished, ActiveRecord::LockWaitTimeout, ActiveRecord::StatementTimeout, ActiveRecord::Deadlocked
99
- sleep 1
100
- retry
101
- end
102
88
  end
103
89
  end
@@ -34,7 +34,7 @@ module CronoTrigger
34
34
 
35
35
  define_model_callbacks :execute, :retry
36
36
 
37
- scope :executables, ->(from: Time.current, limit: CronoTrigger.config.executor_thread * 3 || 100, including_locked: false) do
37
+ scope :executables, ->(from: Time.current, limit: CronoTrigger.config.executor_thread * 3, including_locked: false) do
38
38
  t = arel_table
39
39
 
40
40
  rel = where(t[crono_trigger_column_name(:next_execute_at)].lteq(from))
@@ -63,8 +63,9 @@ module CronoTrigger
63
63
  end
64
64
 
65
65
  module ClassMethods
66
- def executables_with_lock(limit: CronoTrigger.config.executor_thread * 3 || 100)
66
+ def executables_with_lock(limit: CronoTrigger.config.executor_thread * 3)
67
67
  ids = executables(limit: limit).pluck(:id)
68
+ maybe_has_next = !ids.empty?
68
69
  records = []
69
70
  ids.each do |id|
70
71
  transaction do
@@ -75,7 +76,7 @@ module CronoTrigger
75
76
  end
76
77
  end
77
78
  end
78
- records
79
+ [records, maybe_has_next]
79
80
  end
80
81
 
81
82
  def crono_trigger_column_name(name)
@@ -1,3 +1,3 @@
1
1
  module CronoTrigger
2
- VERSION = "0.6.2"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -24,6 +24,7 @@ module CronoTrigger
24
24
  min_threads: 1,
25
25
  max_threads: CronoTrigger.config.executor_thread,
26
26
  max_queue: CronoTrigger.config.executor_thread * 2,
27
+ fallback_policy: :caller_runs,
27
28
  )
28
29
  @execution_counter = Concurrent::AtomicFixnum.new
29
30
  @logger = Logger.new(STDOUT) unless @logger
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: crono_trigger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.6.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-07-20 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: chrono