@@ -45,15 +45,19 @@ class Jobs < SubcommandBase
4545LONG_DESC
4646 # Run an ETL job
4747 def start
48- run_job ( options )
49- rescue Chronicle ::ETL ::JobDefinitionError => e
50- missing_plugins = e . job_definition . errors
51- . select { |error | error . is_a? ( Chronicle ::ETL ::PluginLoadError ) }
52- . map ( &:name )
53- . uniq
48+ job_definition = build_job_definition ( options )
49+
50+ if job_definition . plugins_missing?
51+ missing_plugins = job_definition . errors [ :plugins ]
52+ . select { |error | error . is_a? ( Chronicle ::ETL ::PluginLoadError ) }
53+ . map ( &:name )
54+ . uniq
55+ install_missing_plugins ( missing_plugins )
56+ end
5457
55- install_missing_plugins ( missing_plugins )
56- run_job ( options )
58+ run_job ( job_definition )
59+ rescue Chronicle ::ETL ::JobDefinitionError => e
60+ cli_fail ( message : "Error running job.\n #{ job_definition . errors } " , exception : e )
5761 end
5862
5963 desc "create" , "Create a job"
@@ -104,8 +108,7 @@ def list
104108
105109 private
106110
107- def run_job ( options )
108- job_definition = build_job_definition ( options )
111+ def run_job ( job_definition )
109112 job = Chronicle ::ETL ::Job . new ( job_definition )
110113 runner = Chronicle ::ETL ::Runner . new ( job )
111114 runner . run!
@@ -118,18 +121,10 @@ def install_missing_plugins(missing_plugins)
118121 message += "Do you want to install "
119122 message += missing_plugins . map { |name | "chronicle-#{ name } " . bold } . join ( ", " )
120123 message += " and start the job?"
121- install = prompt . yes? ( message )
122- return unless install
124+ will_install = prompt . yes? ( message )
125+ cli_fail ( message : "Must install #{ missing_plugins . join ( ", " ) } plugin to run job" ) unless will_install
123126
124- spinner = TTY ::Spinner . new ( "[:spinner] Installing plugins..." , format : :dots_2 )
125- spinner . auto_spin
126- missing_plugins . each do |plugin |
127- Chronicle ::ETL ::Registry ::PluginRegistry . install ( plugin )
128- end
129- spinner . success ( "(#{ 'successful' . green } )" )
130- rescue Chronicle ::ETL ::PluginNotAvailableError => e
131- spinner . error ( "Error" . red )
132- Chronicle ::ETL ::Logger . fatal ( "Plugin '#{ e . name } ' could not be installed" . red )
127+ Chronicle ::ETL ::CLI ::Plugins . new . install ( *missing_plugins )
133128 end
134129
135130 # Create job definition by reading config file and then overwriting with flag options
0 commit comments