thecore_background_jobs 2.2.0 → 2.2.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fdcf9fcab7f49e5727cf2d642b3ebe71816f57a56ee584845924309dc52c7b21
|
4
|
+
data.tar.gz: 875489c8fe83a696dbd424e91cbefb84f0aed584e8152595c069cf45da4b3675
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 648ba26852bad9f5755dfa938c7fce6bd3540759a42652cdfdb221277ea5ab3090511d79bd6e7135ee333e9d2e243af0a2c3415d0bc9cf0ad94f6b73b3e0f15e
|
7
|
+
data.tar.gz: af665f56da46427959900d768bc831088fef8419b1e5ed049640ad9d045402dc9653456e215f03c74da77fa786c8a893532843c8abf39b9da0933f8df0c4b5a1
|
@@ -0,0 +1,10 @@
|
|
1
|
+
Rails.application.configure do
|
2
|
+
config.after_initialize do
|
3
|
+
ThecoreBackgroundJobs.update_cron_schedules
|
4
|
+
# Good place for sending concerns about modules
|
5
|
+
# i.e.
|
6
|
+
# ModelName.send(:include, ModelNameConcern)
|
7
|
+
# - ModelNameConcern can be defined in config/initializers folder in order to be sure it's automatically loaded during engine bootstrap
|
8
|
+
ThecoreSettings::Setting.send(:include, ThecoreBackgroundSettingsConcern)
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module ThecoreBackgroundSettingsConcern
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
included do
|
6
|
+
after_save :reload_schedules, if: :saved_change_to_raw?
|
7
|
+
|
8
|
+
def reload_schedules
|
9
|
+
# Reload changes to schedule
|
10
|
+
ThecoreBackgroundJobs.update_cron_schedules if self.ns == "schedules" && !self.raw.blank?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -15,4 +15,46 @@ module ThecoreBackgroundJobs
|
|
15
15
|
delivery_options.merge!({authentication: Settings.ns(:smtp).authentication}) unless Settings.ns(:smtp).authentication.blank?
|
16
16
|
delivery_options
|
17
17
|
end
|
18
|
+
|
19
|
+
def self.update_cron_schedules
|
20
|
+
# {
|
21
|
+
# "AlertForLongTermStockJob"=>{"cron"=>"0 0 9 * * *", "queue"=>"notset_default", "description"=>"This job Alerts a reference email for items in stock for too long", "enabled"=>true, "class"=>"AlertForLongTermStockJob"},
|
22
|
+
# "ScheduleEmployeeReminderForInStockParcelsJob"=>{"cron"=>"0 0 8,14 * * *", "queue"=>"notset_default", "description"=>"This job checks periodically for new received parcels", "enabled"=>true, "class"=>"ScheduleEmployeeReminderForInStockParcelsJob"}
|
23
|
+
# }
|
24
|
+
begin
|
25
|
+
Sidekiq.get_all_schedules.each_pair do |key, config|
|
26
|
+
puts "Key: #{key}, Config: #{config}"
|
27
|
+
schedule = "cron_for_#{key.underscore}"
|
28
|
+
setting = ThecoreSettings::Setting.where(ns: "schedules", key: schedule).pluck(:raw).first
|
29
|
+
puts "Setting is #{schedule} = #{setting}"
|
30
|
+
# Installing initial sidekiq.yml configuration if setting is not present
|
31
|
+
if setting.blank?
|
32
|
+
puts "Setting #{schedule} doesn't exist, creating based on current value: #{config["cron"]}"
|
33
|
+
ThecoreSettings::Setting.create(ns: "schedules", key: schedule, raw: config["cron"])
|
34
|
+
# Settings.ns("schedules").send("#{schedule}=", config["cron"])
|
35
|
+
elsif config["cron"].squeeze(" ").strip != setting.squeeze(" ").strip
|
36
|
+
# If we have a setting and is different from the currently loaded, then replace it
|
37
|
+
# in scheduler configuration
|
38
|
+
puts "Setting #{schedule} exists: #{setting}"
|
39
|
+
Sidekiq.set_schedule(key.underscore, { cron: setting.squeeze(" ").strip, queue: "#{ENV["COMPOSE_PROJECT_NAME"]}_default", class: key })
|
40
|
+
puts "Reloading schedules"
|
41
|
+
SidekiqScheduler::Scheduler.instance.reload_schedule!
|
42
|
+
end
|
43
|
+
end
|
44
|
+
rescue => exception
|
45
|
+
puts "Thecore Background Jobs: REDIS not reachable:"
|
46
|
+
puts exception.message
|
47
|
+
end
|
48
|
+
# check_in_stock_parcels = ThecoreSettings::Setting.where(ns: "schedules", key: "cron_for_check_in_stock_parcels").pluck(:raw).first
|
49
|
+
# unless check_in_stock_parcels.blank?
|
50
|
+
# begin
|
51
|
+
# puts "Setting the schedule during initialization"
|
52
|
+
# Sidekiq.set_schedule('check_in_stock_parcels', { cron: check_in_stock_parcels, queue: "#{ENV["COMPOSE_PROJECT_NAME"]}_default", class: 'ScheduleEmployeeReminderForInStockParcelsJob' })
|
53
|
+
# puts "Reloading schedules during initialization"
|
54
|
+
# SidekiqScheduler::Scheduler.instance.reload_schedule!
|
55
|
+
# rescue => exception
|
56
|
+
# puts exception.message
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
end
|
18
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: thecore_background_jobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriele Tassoni
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thecore_backend_commons
|
@@ -91,7 +91,9 @@ files:
|
|
91
91
|
- README.md
|
92
92
|
- Rakefile
|
93
93
|
- app/workers/demo_worker.rb
|
94
|
+
- config/initializers/after_initialize_for_thecore_backgrond_commons.rb
|
94
95
|
- config/initializers/sidekiq-thecore.rb
|
96
|
+
- config/initializers/thecore_background_settings_concern.rb
|
95
97
|
- config/routes.rb
|
96
98
|
- lib/admin_constraint.rb
|
97
99
|
- lib/tasks/thecore_background_jobs_tasks.rake
|