lib/chronicle/etl/cli/jobs.rb in chronicle-etl-0.4.2 vs lib/chronicle/etl/cli/jobs.rb in chronicle-etl-0.4.3

- old
+ new

@@ -43,19 +43,23 @@ If you do not want to use the command line flags, you can also configure a job with a .yml config file. You can either specify the path to this file or use the filename and place the file in ~/.config/chronicle/etl/jobs/NAME.yml and call it with `--job NAME` LONG_DESC # Run an ETL job def start - run_job(options) - rescue Chronicle::ETL::JobDefinitionError => e - missing_plugins = e.job_definition.errors - .select { |error| error.is_a?(Chronicle::ETL::PluginLoadError) } - .map(&:name) - .uniq + job_definition = build_job_definition(options) - install_missing_plugins(missing_plugins) - run_job(options) + if job_definition.plugins_missing? + missing_plugins = job_definition.errors[:plugins] + .select { |error| error.is_a?(Chronicle::ETL::PluginLoadError) } + .map(&:name) + .uniq + install_missing_plugins(missing_plugins) + end + + run_job(job_definition) + rescue Chronicle::ETL::JobDefinitionError => e + cli_fail(message: "Error running job.\n#{job_definition.errors}", exception: e) end desc "create", "Create a job" # Create an ETL job def create @@ -63,24 +67,21 @@ job_definition.validate! path = File.join('chronicle', 'etl', 'jobs', options[:name]) Chronicle::ETL::Config.write(path, job_definition.definition) rescue Chronicle::ETL::JobDefinitionError => e - Chronicle::ETL::Logger.debug(e.full_message) - Chronicle::ETL::Logger.fatal("Job definition error".red) + cli_fail(message: "Job definition error", exception: e) end desc "show", "Show details about a job" # Show an ETL job def show job_definition = build_job_definition(options) job_definition.validate! puts Chronicle::ETL::Job.new(job_definition) rescue Chronicle::ETL::JobDefinitionError => e - Chronicle::ETL::Logger.debug(e.full_message) - Chronicle::ETL::Logger.fatal("Job definition error".red) - exit 1 + cli_fail(message: "Job definition error", exception: e) end desc "list", "List all available jobs" # List available ETL jobs def list @@ -100,19 +101,16 @@ puts "Available jobs:" table = TTY::Table.new(headers, job_details) puts table.render(indent: 0, padding: [0, 2]) rescue Chronicle::ETL::ConfigError => e - Chronicle::ETL::Logger.debug(e.full_message) - Chronicle::ETL::Logger.fatal("Error reading config. #{e.message}".red) - exit 1 + cli_fail(message: "Config error. #{e.message}", exception: e) end private - def run_job(options) - job_definition = build_job_definition(options) + def run_job(job_definition) job = Chronicle::ETL::Job.new(job_definition) runner = Chronicle::ETL::Runner.new(job) runner.run! end @@ -121,21 +119,13 @@ prompt = TTY::Prompt.new message = "Plugin#{'s' if missing_plugins.count > 1} specified by job not installed.\n" message += "Do you want to install " message += missing_plugins.map { |name| "chronicle-#{name}".bold}.join(", ") message += " and start the job?" - install = prompt.yes?(message) - return unless install + will_install = prompt.yes?(message) + cli_fail(message: "Must install #{missing_plugins.join(", ")} plugin to run job") unless will_install - spinner = TTY::Spinner.new("[:spinner] Installing plugins...", format: :dots_2) - spinner.auto_spin - missing_plugins.each do |plugin| - Chronicle::ETL::Registry::PluginRegistry.install(plugin) - end - spinner.success("(#{'successful'.green})") - rescue Chronicle::ETL::PluginNotAvailableError => e - spinner.error("Error".red) - Chronicle::ETL::Logger.fatal("Plugin '#{e.name}' could not be installed".red) + Chronicle::ETL::CLI::Plugins.new.install(*missing_plugins) end # Create job definition by reading config file and then overwriting with flag options def build_job_definition(options) definition = Chronicle::ETL::JobDefinition.new