Module: S3::NewDeletedRecordsService
- Defined in:
- app/services/s3/new_deleted_records_service.rb
Constant Summary collapse
- DB_TABLES =
%w$ shifts teams users contracts infos posts topics verlof_verzoeken$
Class Method Summary collapse
- .filter_records ⇒ Object
- .get_records(db_table:, start_date:, end_date:, env_id:) ⇒ Object
- .no_deleted_at? ⇒ Boolean
- .query_records ⇒ Object
- .set_file_name ⇒ Object
- .validate_args ⇒ Object
Class Method Details
.filter_records ⇒ Object
43 44 45 46 |
# File 'app/services/s3/new_deleted_records_service.rb', line 43 def filter_records return if no_deleted_at? @records.select! { |record| @date_range.include?(Date.parse(record[:deleted_at])) } end |
.get_records(db_table:, start_date:, end_date:, env_id:) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'app/services/s3/new_deleted_records_service.rb', line 6 def get_records(db_table:, start_date:, end_date:, env_id:) @date_range = Date.parse(start_date)..Date.parse(end_date) @s3 = Aws::S3::Client.new @db_table = db_table @env_id = env_id set_file_name validate_args query_records filter_records @records end |
.no_deleted_at? ⇒ Boolean
48 49 50 |
# File 'app/services/s3/new_deleted_records_service.rb', line 48 def no_deleted_at? %w[infos].include? @db_table # files without deleted_at field end |
.query_records ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/services/s3/new_deleted_records_service.rb', line 28 def query_records # Previously (before adding 'topics') the request bucket was 'eitje-deleted-jurr' # but somehow topics break if we dont request the bucket '-2'. Now for other tables # the original returns waaaaay many records, so probably does not filter by date or # something. Change for now and investigate if shit goes BG. begin file = @s3.get_object(bucket: 'eitje-deleted-jurr-2', key: @file_name) @records = JSON.parse(file.body.read.as_json).map(&:symbolize_keys) rescue Aws::S3::Errors::NoSuchKey @records = [] # files are only generated when an env has some deleted envs, through by uploading them old-style first end end |
.set_file_name ⇒ Object
24 25 26 |
# File 'app/services/s3/new_deleted_records_service.rb', line 24 def set_file_name @file_name = "env_#{@env_id}_deleted_#{@db_table}.json" end |
.validate_args ⇒ Object
20 21 22 |
# File 'app/services/s3/new_deleted_records_service.rb', line 20 def validate_args throw :db_table_name_is_not_valid unless DB_TABLES.include?(@db_table) end |