ASSETS.cli do |cli| # rubocop:disable Metrics/BlockLength ASSETS.config.workflow do |wf| # rubocop:disable Metrics/BlockLength rescued = false # default rescue wf.rescue do |err, io| next io if rescued rescued = true log(:debug) { err.patch_full_message } wf.run(:close, io: io) rescue StandardError => e puts "Some problem in workflow.rescue: #{e}" end wf.on(:options) do |_wf_opt, io| cli.config.usecases.cli_apply(io: io) io.new(options: cli.config.options_set.process(io: io)) end wf.for(:load) do |wf_load| wf_load.for(:input) do |wf_in| wf_in.on(:get) do |_wf_ig, io| cases_with_input = cli.config.usecases.active(io: io).select do |usecase, _data| io.class.input_required?(usecase.type) end input_is_required = !cases_with_input.empty? || options.dig(:input, :entries_from) missing_input = !input || input.empty? next unless missing_input && input_is_required if options.dig(:input, :entries_from) io.new(input: cli.config.input.get(io: io)) else opt_case = cases_with_input.values.first.option io.new(input: cli.config.input.get(io: io, option: opt_case)) end end wf_in.on(:filter) do |_wf_if, io| next unless input && !input.empty? io.new(input: cli.config.input_filters.process(io: io)) end end wf_load.for(:people) do |wf_peo| wf_peo.on(:get) do |_wf_pg, io| cases_with_people = cli.config.usecases.active(io: io).select do |usecase, _data| io.class.people_required?(usecase.type) end next if cases_with_people.empty? && !options.dig(:people, :get) io.new(people: cli.config.people(io: io)) end wf_peo.on(:filter) do |_wf_pf, io| next unless people && !people.empty? io.new(people: cli.config.people_filters.process(io: io)) end end end wf.before(:usecases) do |_wf_ca, io| # save partial entries -> should be native to session.workflow get_people = options.dig(:people, :get) partial_update = get_people && get_people[:type] == :partial if !options[:dry_run] && partial_update partial_file = session.config.people.partial_cache session.file_manager.save_json(io.people, partial_file, :timestamp) end end wf.on(:usecases) do |_wf_ca, io| unless cli.config.usecases.process(io: io) log(:info) { "No update operation specified... quitting" } exit 0 end end wf.before(:launch_jobs) do |_wf_jobs, io| available_args = cli.config.available_option_args SCR.stop_on_unknown!(all_available: available_args) end wf.on(:launch_jobs) do session.jobs_launch(simulate: options[:dry_run]) end wf.before(:post_launch) do |wf_post, io| next wf_post.skip! if session.post_launch.empty? run_it = !options[:dry_run] || options.dig(:post_launch, :run) unless run_it wf_post.skip! log(:info) { msg = "Although there are post_launch cases, they will NOT be RUN" msg += ", because we are in dry-run (simulate)." if options[:dry_run] msg } next end get_people = options.dig(:people, :get) partial_update = get_people && get_people[:type] == :partial refresh_data = !options[:dry_run] && partial_update unless refresh_data log(:info) { msg = "Although there are post_launch cases, data will not be refreshed before their run" if io.options[:dry_run] msg += ", because we are in dry-run (simulate)." elsif !partial_update msg += ", because it is not a partial update (-get-partial option not present)." end msg } next end # get target people afresh peo_aux = session.micro.people_refresh(people: people, include_created: true) io.base.new(people: peo_aux) end wf.for(:post_launch) do |wf_post| wf_post.on(:usecases) do |_wf_pu, io| session.post_launch.each do |use| use.launch(io: io).base rescue Eco::API::UseCases::BaseIO::MissingParameter => e raise unless e.required == :people log(:debug) { "Skipping use case '#{use.name}' -- no base people detected for the current run" } end end wf_post.on(:launch_jobs) do |_wf_pl, _io| session.jobs_launch(simulate: options[:dry_run]) end end wf.on(:report) do |_wf_rep, io| if (file = options.dig(:report, :people, :csv)) options.deep_merge!(export: { options: {internal_names: true, nice_header: true, split_schemas: true}, file: {name: file, format: :csv} }) aux_io = io.new(people: people.updated_or_created) session.process_case("to-csv", io: aux_io, type: :export) end end wf.on(:end) do |_wf_end, io| get_people = options.dig(:people, :get) partial_update = get_people && get_people[:type] == :partial unless !options[:end_get] || options[:dry_run] || partial_update people_update_cases = cli.config.usecases.active(io: io).any? do |usecase, _data| %i[transform sync].any? { |type| usecase.type == type } end if !people_update_cases # Prevent getting people when there were no use cases that used them log(:info) { "Won't be recaching people, as there haven't been any targetted updates" } elsif !people people = session.micro.people_cache io.new(people: people) end end end end end