Sha256: 5d8fb069cd865d19fa8abff5afb5175e4465356848ed5355f97caa7768ce2841
Contents?: true
Size: 1.98 KB
Versions: 3
Compression:
Stored size: 1.98 KB
Contents
class Eco::API::Common::Loaders::Workflow::Mailer < Eco::API::Common::Loaders::Workflow ORG = 'your organization'.freeze TRACE_COUNT = 3 inheritable_class_vars :config_block config_block do #puts "running from class #{self}" exception do |err, io| self.error = err log(:debug) { err.patch_full_message } workflow.run(:close, io: io) end after(:close) do |_wf, io| next if options.dig(:workflow, :no_email) next unless session.mailer? next if session.config.dry_run? next unless session.config.run_mode_remote? next unless some_update?(io) || error? subject = base_subject if session.job_groups.empty? && error? subject = "#{subject} - Exception!" session.mail(subject: subject, body: errors_n_warnings(io)) else subject = "#{subject} & Errors" if session.job_groups.errors? subject = "#{subject} - Exception!" if error? msg = "#{session.summary}\n" msg += errors_n_warnings(io) session.mail(subject: subject, body: msg) unless msg.strip.empty? end end end class << self attr_accessor :error def org_name self::ORG end def base_subject "#{org_name} (#{active_enviro}) at #{Time.now.iso8601}" end def some_update?(io) cli.config.usecases.active(io: io).any? do |usecase, data| %i[transform sync].any? { |type| usecase.type == type } end end def error? !!error end def errors_n_warnings(io) [error_message, log_err_n_warn(io)].join("\n") end def log_err_n_warn(io) warn_errors = io.logger.cache.logs(level: %i[error warn]) return if warn_errors.empty? "WARNINGS & ERRORS:\n#{warn_errors.join('')}\n" end def error_message error&.patch_full_message(trace_count: 3) end def trace_count self::TRACE_COUNT end end end
Version data entries
3 entries across 3 versions & 1 rubygems