Skip to content

Commit fb55ef6

Browse files
committed
add daily script
1 parent ae92ee0 commit fb55ef6

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

lib/cli.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,20 @@ def full
1919
ProcessLdap.new(**new_options).process
2020
end
2121

22+
desc "daily FROM_DATE", "Processes all users in mcommunity modified or created after the FROM_DATE 000000 UTC. For full coverage, the FROM_DATE for a daily cronjob should be yesterday."
23+
method_option :output_directory, type: :string, required: false, default: S.output_directory, desc: "Path to directory for output files"
24+
method_option :base_name, type: :string, required: false, default: "patron_daily_#{Date.today.strftime("%Y%m%d")}", desc: "Basename for files put in the output directory"
25+
method_option :size, type: :numeric, required: false, desc: "The maximum number of results to request"
26+
def daily(from_date)
27+
new_options = {
28+
date: format_date(from_date),
29+
base_name: options[:base_name],
30+
output_directory: options[:output_directory],
31+
size: options[:size]
32+
}
33+
ProcessLdapDaily.new(**new_options).process
34+
end
35+
2236
desc "range", "processes users for a given date range"
2337
method_option :start_date, type: :string, required: true
2438
method_option :end_date, type: :string, required: false, desc: "The end of the date range. Inclusive. If not given, it defaults to whatever start_date is."
@@ -54,6 +68,8 @@ def ldap(uniqname)
5468
def format_date(date)
5569
date = DateTime.parse(date) if date.is_a? String
5670
date.strftime("%Y%m%d")
71+
rescue Date::Error
72+
abort("ERROR: parameter/option #{date} must be a valid date string\n")
5773
end
5874
end
5975
end

lib/process_ldap.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,10 @@ def unexpected_size_limit?(ldap_result_code)
138138
end
139139

140140
class ProcessLdapDaily < ProcessLdap
141-
def initialize(date:)
142-
@date = DateTime.parse(date).strftime("%Y%m%d") + "050000.0Z" # just set it to EST diff from UTC
141+
def initialize(date:, output_directory:, base_name:, size: nil)
142+
@size = size
143+
@file_base = File.join(output_directory, base_name)
144+
@date = DateTime.parse(date).strftime("%Y%m%d") + "000000Z"
143145
end
144146

145147
def script_type
@@ -161,8 +163,8 @@ class ProcessLdapModifyDateRange < ProcessLdap
161163
def initialize(start_date:, output_directory:, base_name:, end_date: start_date, size: nil)
162164
@size = size
163165
@file_base = File.join(output_directory, base_name)
164-
@start_date = DateTime.parse(start_date).strftime("%Y%m%d") + "000000Z" # just set it to EDT diff from UTC
165-
@end_date = DateTime.parse(end_date).strftime("%Y%m%d") + "235959Z" # just set it to EDT diff from UTC
166+
@start_date = DateTime.parse(start_date).strftime("%Y%m%d") + "000000Z"
167+
@end_date = DateTime.parse(end_date).strftime("%Y%m%d") + "235959Z"
166168
raise StandardError, "start_date must be before end_date" if DateTime.parse(@start_date) > DateTime.parse(@end_date)
167169
end
168170

0 commit comments

Comments
 (0)