class EcoRake module Lib module People # The top level task that organizes all the people sync class SyncProcess < EcoRake::Lib::People::SyncRely attr_const :do_decrypt, default: false attr_const :target_task attr_const :target_enviro, required: true option_reopen :enviro, default_lookup: :target_enviro attr_const :local_folder, default: '.' attr_const :mail_to option_reopen :folder, default_lookup: :local_folder def task(*_args) upsert_local_dir(options[:folder]) sh_continue rake_sftp_get if do_decrypt failed_decryption_notify unless 0 == sh_continue(rake_decrypt) end sh_continue rake_sync_command return if options[:simulate] sh_continue rake_sftp_archive sh_continue rake_files_purge('cache') sh_continue rake_files_purge('requests') end private def rake_sftp_get rake_command('csv:sftp', *forward_options(:enviro, :folder), '-t') end def rake_sftp_archive rake_command('csv:sftp', *forward_options(:enviro, :folder), '-a') end def rake_decrypt array_cmd('rake csv:decrypt', '--', forward_option(:folder)).join(" ") end def rake_files_purge(folder, operation: '--remove') rake_command('logs:purge', *forward_options(:enviro), "-d #{folder}", operation) end def failed_decryption_notify msg = 'File decryption failed' puts msg exit 1 if options[:simulate] exit 1 unless inbox = mail_to email(enviro: target_enviro, to: inbox, subject: msg, body: msg) exit 1 end end end end end