solid_queue 0.3.0 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -10
- data/app/models/solid_queue/blocked_execution.rb +16 -10
- data/app/models/solid_queue/claimed_execution.rb +11 -4
- data/app/models/solid_queue/execution/dispatching.rb +2 -3
- data/app/models/solid_queue/execution.rb +32 -15
- data/app/models/solid_queue/failed_execution.rb +10 -6
- data/app/models/solid_queue/job/executable.rb +1 -1
- data/app/models/solid_queue/job/schedulable.rb +1 -1
- data/app/models/solid_queue/process/prunable.rb +6 -5
- data/app/models/solid_queue/process.rb +13 -6
- data/app/models/solid_queue/recurring_execution.rb +3 -3
- data/app/models/solid_queue/scheduled_execution.rb +3 -1
- data/app/models/solid_queue/semaphore.rb +1 -1
- data/lib/active_job/queue_adapters/solid_queue_adapter.rb +4 -0
- data/lib/generators/solid_queue/install/templates/config.yml +1 -1
- data/lib/puma/plugin/solid_queue.rb +1 -0
- data/lib/solid_queue/app_executor.rb +1 -1
- data/lib/solid_queue/dispatcher/recurring_task.rb +13 -7
- data/lib/solid_queue/dispatcher.rb +4 -4
- data/lib/solid_queue/engine.rb +5 -3
- data/lib/solid_queue/log_subscriber.rb +164 -0
- data/lib/solid_queue/processes/base.rb +16 -0
- data/lib/solid_queue/processes/interruptible.rb +1 -1
- data/lib/solid_queue/processes/poller.rb +7 -5
- data/lib/solid_queue/processes/registrable.rb +5 -23
- data/lib/solid_queue/processes/runnable.rb +4 -3
- data/lib/solid_queue/processes/signals.rb +1 -1
- data/lib/solid_queue/supervisor.rb +25 -24
- data/lib/solid_queue/version.rb +1 -1
- data/lib/solid_queue/worker.rb +6 -6
- data/lib/solid_queue.rb +24 -11
- metadata +27 -15
- data/lib/solid_queue/recurring_tasks/manager.rb +0 -31
- data/lib/solid_queue/recurring_tasks/schedule.rb +0 -58
- data/lib/solid_queue/recurring_tasks/task.rb +0 -87
@@ -1,58 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SolidQueue
|
4
|
-
module RecurringTasks
|
5
|
-
class Schedule
|
6
|
-
include AppExecutor
|
7
|
-
|
8
|
-
attr_reader :configured_tasks, :scheduled_tasks
|
9
|
-
|
10
|
-
def initialize(tasks)
|
11
|
-
@configured_tasks = Array(tasks).map { |task| Task.wrap(task) }
|
12
|
-
@scheduled_tasks = Concurrent::Hash.new
|
13
|
-
end
|
14
|
-
|
15
|
-
def load_tasks
|
16
|
-
configured_tasks.each do |task|
|
17
|
-
load_task(task)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
def load_task(task)
|
22
|
-
scheduled_tasks[task.key] = schedule(task)
|
23
|
-
end
|
24
|
-
|
25
|
-
def unload_tasks
|
26
|
-
scheduled_tasks.values.each(&:cancel)
|
27
|
-
scheduled_tasks.clear
|
28
|
-
end
|
29
|
-
|
30
|
-
def tasks
|
31
|
-
configured_tasks.each_with_object({}) { |task, hsh| hsh[task.key] = task.to_h }
|
32
|
-
end
|
33
|
-
|
34
|
-
def inspect
|
35
|
-
configured_tasks.map(&:to_s).join(" | ")
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
def schedule(task)
|
40
|
-
scheduled_task = Concurrent::ScheduledTask.new(task.delay_from_now, args: [ self, task, task.next_time ]) do |thread_schedule, thread_task, thread_task_run_at|
|
41
|
-
thread_schedule.load_task(thread_task)
|
42
|
-
|
43
|
-
wrap_in_app_executor do
|
44
|
-
thread_task.enqueue(at: thread_task_run_at)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
scheduled_task.add_observer do |_, _, error|
|
49
|
-
# Don't notify on task cancellation before execution, as this will happen normally
|
50
|
-
# as part of unloading tasks
|
51
|
-
handle_thread_error(error) if error && !error.is_a?(Concurrent::CancelledOperationError)
|
52
|
-
end
|
53
|
-
|
54
|
-
scheduled_task.tap(&:execute)
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
require "fugit"
|
2
|
-
|
3
|
-
module SolidQueue
|
4
|
-
module RecurringTasks
|
5
|
-
class Task
|
6
|
-
class << self
|
7
|
-
def wrap(args)
|
8
|
-
args.is_a?(self) ? args : from_configuration(args.first, **args.second)
|
9
|
-
end
|
10
|
-
|
11
|
-
def from_configuration(key, **options)
|
12
|
-
new(key, class_name: options[:class], schedule: options[:schedule], arguments: options[:args])
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_reader :key, :schedule, :class_name, :arguments
|
17
|
-
|
18
|
-
def initialize(key, class_name:, schedule:, arguments: nil)
|
19
|
-
@key = key
|
20
|
-
@class_name = class_name
|
21
|
-
@schedule = schedule
|
22
|
-
@arguments = Array(arguments)
|
23
|
-
end
|
24
|
-
|
25
|
-
def delay_from_now
|
26
|
-
[ (next_time - Time.current).to_f, 0 ].max
|
27
|
-
end
|
28
|
-
|
29
|
-
def next_time
|
30
|
-
parsed_schedule.next_time.utc
|
31
|
-
end
|
32
|
-
|
33
|
-
def enqueue(at:)
|
34
|
-
if using_solid_queue_adapter?
|
35
|
-
perform_later_and_record(run_at: at)
|
36
|
-
else
|
37
|
-
perform_later
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
def valid?
|
42
|
-
parsed_schedule.instance_of?(Fugit::Cron)
|
43
|
-
end
|
44
|
-
|
45
|
-
def to_s
|
46
|
-
"#{class_name}.perform_later(#{arguments.map(&:inspect).join(",")}) [ #{parsed_schedule.original.to_s} ]"
|
47
|
-
end
|
48
|
-
|
49
|
-
def to_h
|
50
|
-
{
|
51
|
-
schedule: schedule,
|
52
|
-
class_name: class_name,
|
53
|
-
arguments: arguments
|
54
|
-
}
|
55
|
-
end
|
56
|
-
|
57
|
-
private
|
58
|
-
def using_solid_queue_adapter?
|
59
|
-
job_class.queue_adapter_name.inquiry.solid_queue?
|
60
|
-
end
|
61
|
-
|
62
|
-
def perform_later_and_record(run_at:)
|
63
|
-
RecurringExecution.record(key, run_at) { perform_later.provider_job_id }
|
64
|
-
end
|
65
|
-
|
66
|
-
def perform_later
|
67
|
-
job_class.perform_later(*arguments_with_kwargs)
|
68
|
-
end
|
69
|
-
|
70
|
-
def arguments_with_kwargs
|
71
|
-
if arguments.last.is_a?(Hash)
|
72
|
-
arguments[0...-1] + [ Hash.ruby2_keywords_hash(arguments.last) ]
|
73
|
-
else
|
74
|
-
arguments
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
def parsed_schedule
|
79
|
-
@parsed_schedule ||= Fugit.parse(schedule)
|
80
|
-
end
|
81
|
-
|
82
|
-
def job_class
|
83
|
-
@job_class ||= class_name.safe_constantize
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|