Sha256: dccc47c2b0d0fabd70a5a258c372b62ea80737cd94c877e0e817747145ad216c

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

module Actions
  module RemoteExecution
    class ProxyAction < ::Actions::ProxyAction
      include Actions::RemoteExecution::TemplateInvocationProgressLogging

      def on_data(data, meta = {})
        super
        process_proxy_data(output[:proxy_output])
      end

      def run(event = nil)
        with_template_invocation_error_logging { super }
      end

      private

      def get_proxy_data(response)
        data = super
        process_proxy_data(data)
        data
      end

      def process_proxy_data(data)
        events = data['result'].map do |update|
          {
            template_invocation_id: template_invocation.id,
            event: update['output'],
            timestamp: Time.at(update['timestamp']).getlocal,
            event_type: update['output_type'],
          }
        end
        if data['exit_status']
          events << {
            template_invocation_id: template_invocation.id,
            event: data['exit_status'],
            timestamp: events.last[:timestamp] + 0.0001,
            event_type: 'exit',
          }
        end
        events.each_slice(1000) do |batch|
          TemplateInvocationEvent.upsert_all(batch, unique_by: [:template_invocation_id, :timestamp, :event_type]) # rubocop:disable Rails/SkipsModelValidations
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
foreman_remote_execution-8.1.0 app/lib/actions/remote_execution/proxy_action.rb