Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FBZ-10492] Fix Custom Cron for DB and Util instances #133

Merged
merged 3 commits into from Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
96 changes: 48 additions & 48 deletions cookbooks/ey-cron/recipes/custom.rb
Expand Up @@ -22,65 +22,65 @@ def delete_cron_jobs_not_in_custom(user, crons)
end
end

if crontab_instance?(node)
if node["custom_crons"]
# Find all cron jobs specified in attributes/cron.rb where current node matches instance_name
named_crons = node["custom_crons"].find_all { |c| c[:instance_name] == node["dna"]["name"] }
if node["custom_crons"]
# Find all cron jobs specified in attributes/cron.rb where current node matches instance_name
named_crons = node["custom_crons"].find_all { |c| c["instance_name"] == node["dna"]["name"] }

# Find all cron jobs for utility instances
util_crons = node["custom_crons"].find_all { |c| c[:instance_name] == "util" }
# Find all cron jobs for utility instances
util_crons = node["custom_crons"].find_all { |c| c["instance_name"] == "util" }

# Find all cron jobs for app master only
app_master_crons = node["custom_crons"].find_all { |c| c[:instance_name] == "app_master" }
# Find all cron jobs for app master only
app_master_crons = node["custom_crons"].find_all { |c| c["instance_name"] == "app_master" }

# Find all cron jobs for solo only
solo_crons = node["custom_crons"].find_all { |c| c[:instance_name] == "solo" }
# Find all cron jobs for solo only
solo_crons = node["custom_crons"].find_all { |c| c["instance_name"] == "solo" }

# Find all cron jobs for application instances
app_crons = node["custom_crons"].find_all { |c| c[:instance_name] == "app" }
# Find all cron jobs for application instances
app_crons = node["custom_crons"].find_all { |c| c["instance_name"] == "app" }

# Find all cron jobs for ALL instances
all_crons = node["custom_crons"].find_all { |c| c[:instance_name] == "all" }
# Find all cron jobs for ALL instances
all_crons = node["custom_crons"].find_all { |c| c["instance_name"] == "all" }

# Find all cron jobs for Database instances
db_crons = node["custom_crons"].find_all { |c| c[:instance_name] == "db" }
# Find all cron jobs for Database instances
db_crons = node["custom_crons"].find_all { |c| c["instance_name"] == "db" }

crons = all_crons + named_crons
if node["dna"]["instance_role"] == "util"
crons += util_crons
end
crons = all_crons + named_crons

if node["dna"]["instance_role"] == "app_master"
crons += app_master_crons
end
if node["dna"]["instance_role"] == "util"
crons += util_crons
end

if node["dna"]["instance_role"] == "solo"
crons += solo_crons
end
if node["dna"]["instance_role"] == "app_master"
crons += app_master_crons
end

if node["dna"]["instance_role"] == "app" || node["dna"]["instance_role"] == "app_master"
crons += app_crons
end
if node["dna"]["instance_role"] == "solo"
crons += solo_crons
end

if node["dna"]["instance_role"] == "db_master" || node["dna"]["instance_role"] == "db_slave"
crons += db_crons
end
else
crons = []
if node["dna"]["instance_role"] == "app" || node["dna"]["instance_role"] == "app_master"
crons += app_crons
end
delete_cron_jobs_not_in_custom(node["owner_name"], crons)
delete_cron_jobs_not_in_custom("root", crons)
crons.each do |c|
custom_cron_name = "custom_cron_#{c['name']}"
cron custom_cron_name do
user node["owner_name"]
action :create
minute c[:time].split[0]
hour c[:time].split[1]
day c[:time].split[2]
month c[:time].split[3]
weekday c[:time].split[4]
command c[:command]
end

if node["dna"]["instance_role"] == "db_master" || node["dna"]["instance_role"] == "db_slave"
crons += db_crons
end
else
crons = []
end

delete_cron_jobs_not_in_custom(node["owner_name"], crons)
delete_cron_jobs_not_in_custom("root", crons)
crons.each do |c|
custom_cron_name = "custom_cron_#{c['name']}"
cron custom_cron_name do
user node["owner_name"]
action :create
minute c[:time].split[0]
hour c[:time].split[1]
day c[:time].split[2]
month c[:time].split[3]
weekday c[:time].split[4]
command c[:command]
end
end
@@ -1,5 +1,5 @@
# Add crons here
default[:custom_crons] = []
default["custom_crons"] = []
# Example:
# default[:custom_crons] = [{:name => "test1", :time => "10 * * * *", :command => "echo 'test1'", :instance_name => "cron"},
# {:name => "test2", :time => "10 1 * * *", :command => "echo 'test2'", :instance_name => "cron"}]
# default["custom_crons"] = [{name: "test1", time: "10 * * * *", command: "echo 'test1'", instance_name: "cron"},
# {name: "test2", time: "10 1 * * *", command: "echo 'test2'", instance_name: "cron"}]