lib/eco/api/session/batch/job.rb in eco-helpers-1.5.13 vs lib/eco/api/session/batch/job.rb in eco-helpers-1.5.14

- old
+ new

@@ -69,16 +69,10 @@ # @return [Eco::API::Session::Batch::Jobs] group of subjobs of this `Batch::Job` def subjobs @subjobs ||= Eco::API::Session::Batch::Jobs.new(enviro, name: "childs-of:#{self.name}") end - def subjobs_add(name = "ad-hoc:job-from:#{self.name}", usecase: self.usecase, &block) - dup(name, usecase: usecase).tap do |subjob| - subjobs.add(subjob, &block) - end - end - # @return [Boolean] `true` if the current batch job is a result of an error_handler def error_handler? usecase? && usecase.is_a?(Eco::API::Error::Handler) end @@ -209,10 +203,11 @@ msg << "Batch Policy Uncompliance:" msg << batch_policy.uncompliance(request_stats) end msg << status.errors.message unless !status + msg << subjobs_summary end end.join("\n") end private @@ -236,11 +231,11 @@ end # Applies the changes introduced by api policies def apply_policies(pre_queue) people(pre_queue).tap do |entries| - policies = session.config.policies + policies = session.policies unless policies.empty? || options.dig(:skip, :api_policies) policies.launch(people: entries, session: session, options: options, job: self) end end end @@ -303,9 +298,24 @@ # Keep a copy of the requests for future reference def backup_update(requests) dir = config.people.requests_folder file = File.join(dir, "#{type}_data.json") file_manager.save_json(requests, file, :timestamp) + end + + # Adds a job tied to the current job + # Used with error handlers that need their own job to run + def subjobs_add(name = "ad-hoc:job-from:#{self.name}", usecase: self.usecase, &block) + dup(name, usecase: usecase).tap do |subjob| + subjobs.add(subjob, &block) + end + end + + def subjobs_summary + return "" unless subjobs.count > 0 + [].tap do |msg| + subjobs.map {|subjob| msg << subjob.summary} + end.join("\n") end end end end