remove week_of_month dependency
we only used it for one thing, and honestly with all of the dynamic method dispatch it's not clear what it's even doing, so just do the math ourselves Change-Id: I17b601732d7b6e5e2236eb01e9ef368fc9d1fa89 Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/326665 Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com> Reviewed-by: Jacob Burroughs <jburroughs@instructure.com> QA-Review: Cody Cutrer <cody@instructure.com> Product-Review: Cody Cutrer <cody@instructure.com> Build-Review: Cody Cutrer <cody@instructure.com>
This commit is contained in:
parent
b3fbae61fe
commit
2cfeebb3e7
|
@ -127,10 +127,6 @@ gem "twilio-ruby", "~> 6.4", require: false
|
|||
gem "vault", "~> 0.17", require: false
|
||||
gem "vericite_api", "1.5.3"
|
||||
gem "wcag_color_contrast", "0.1.0"
|
||||
gem "week_of_month",
|
||||
"1.2.5",
|
||||
github: "instructure/week-of-month",
|
||||
ref: "b3013639e9474f302b5a6f27e4e45313e8d24902"
|
||||
|
||||
gem "faraday", "~> 2.7"
|
||||
|
||||
|
|
|
@ -6,13 +6,6 @@ GIT
|
|||
ffi-icu (0.4.0)
|
||||
ffi (~> 1.0, >= 1.0.9)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/instructure/week-of-month.git
|
||||
revision: b3013639e9474f302b5a6f27e4e45313e8d24902
|
||||
ref: b3013639e9474f302b5a6f27e4e45313e8d24902
|
||||
specs:
|
||||
week_of_month (1.2.5)
|
||||
|
||||
GIT
|
||||
remote: https://github.com/kreynolds/cassandra-cql.git
|
||||
revision: 02b5abbe441a345c051a180327932566fd66bb36
|
||||
|
@ -1368,7 +1361,6 @@ DEPENDENCIES
|
|||
vericite_api (= 1.5.3)
|
||||
wcag_color_contrast (= 0.1.0)
|
||||
webmock (~> 3.18)
|
||||
week_of_month (= 1.2.5)!
|
||||
workflow!
|
||||
yard (~> 0.9)
|
||||
yard-appendix (= 0.1.8)
|
||||
|
|
|
@ -159,23 +159,45 @@ Rails.application.config.after_initialize do
|
|||
def next_maintenance_window
|
||||
return nil unless maintenance_window_start_hour
|
||||
|
||||
start_day = DateTime.now
|
||||
# This array is effectively 1 indexed
|
||||
relevant_weeks = maintenance_window_weeks_of_month.map { |i| WeekOfMonth::Constant::WEEKS_IN_SEQUENCE[i] }
|
||||
maintenance_days = relevant_weeks.map do |ordinal|
|
||||
start_day.send("#{ordinal}_#{maintenance_window_weekday}_in_month".downcase)
|
||||
end + relevant_weeks.map do |ordinal|
|
||||
(start_day + 1.month).send("#{ordinal}_#{maintenance_window_weekday}_in_month".downcase)
|
||||
now = Time.now.utc
|
||||
date = nil
|
||||
weekday = maintenance_window_weekday
|
||||
weeks = maintenance_window_weeks_of_month
|
||||
loop do
|
||||
first_date = first_given_weekday_of_month(weekday, now)
|
||||
# look at the 1st, 3rd, etc. weekday of this month, and see if it's in the future
|
||||
weeks.each do |i|
|
||||
new_date = first_date.advance(weeks: i - 1)
|
||||
# make sure we didn't overrun the current month, like if there's not a 5th thursday this month
|
||||
if new_date.future? && new_date.month == now.month
|
||||
date = new_date
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
break if date
|
||||
|
||||
# search the next month
|
||||
now = now.next_month
|
||||
end
|
||||
|
||||
next_day = maintenance_days.find(&:future?)
|
||||
# Time offsets are strange
|
||||
start_at = next_day.utc.beginning_of_day - maintenance_window_start_hour.hours + maintenance_window_offset.minutes
|
||||
start_at = date.beginning_of_day - maintenance_window_start_hour.hours + maintenance_window_offset.minutes
|
||||
end_at = start_at + maintenance_window_duration
|
||||
|
||||
[start_at, end_at]
|
||||
end
|
||||
|
||||
# Finds the first day of the month that is a given weekday
|
||||
#
|
||||
# @param [Integer] which weekday we're looking for
|
||||
# @param [Time] start_ref the month to look in
|
||||
def first_given_weekday_of_month(weekday, start_ref)
|
||||
date = start_ref.beginning_of_month
|
||||
date = date.next_day until date.wday == weekday
|
||||
date
|
||||
end
|
||||
|
||||
def maintenance_window_start_hour
|
||||
Setting.get("maintenance_window_start_hour", nil)&.to_i
|
||||
end
|
||||
|
@ -189,12 +211,15 @@ Rails.application.config.after_initialize do
|
|||
ActiveSupport::Duration.parse(Setting.get("maintenance_window_duration", "PT2H"))
|
||||
end
|
||||
|
||||
# @return [Integer] the weekday of the maintenance window
|
||||
def maintenance_window_weekday
|
||||
Setting.get("maintenance_window_weekday", "thursday").downcase
|
||||
Date::DAYNAMES.index(Setting.get("maintenance_window_weekday", "thursday").capitalize)
|
||||
end
|
||||
|
||||
# @return [Array<Integer>]
|
||||
# the weeks of the month that the maintenance window occurs on, sorted and 1-indexed
|
||||
def maintenance_window_weeks_of_month
|
||||
Setting.get("maintenance_window_weeks_of_month", "1,3").split(",").map(&:to_i)
|
||||
Setting.get("maintenance_window_weeks_of_month", "1,3").split(",").map(&:to_i).sort
|
||||
end
|
||||
|
||||
def self.send_in_each_region(klass, method, enqueue_args, *args, **kwargs)
|
||||
|
|
Loading…
Reference in New Issue