Sha256: 6872d9b1ecfb42be1c043e7e98ccdb83d1ad150e50e3d5b7f8bae44208629548

Contents?: true

Size: 1.91 KB

Versions: 1

Compression:

Stored size: 1.91 KB

Contents

# frozen_string_literal: true

module Legion::Extensions::Lex # rubocop:disable Style/ClassAndModuleChildren
  module Runners
    module Runner
      include Legion::Extensions::Helpers::Lex

      def create(extension_id:, name:, active: 1, **opts)
        exist = Legion::Data::Model::Runner.where(name: name.to_s).where(extension_id: extension_id).first
        unless exist.nil?
          update_hash = { runner_id: exist.values[:id], name: name, active: active, **opts }
          return Legion::Runner.run(runner_class: 'Legion::Extensions::Lex::Runners::Runner',
                                    function:     'update',
                                    args:         update_hash,
                                    parent_id:    opts[:task_id],
                                    master_id:    opts[:master_id])
        end
        insert = { extension_id: extension_id, name: name.to_s, active: active, namespace: opts[:namespace] }
        insert[:queue] = opts.key?(:queue) ? opts[:queue] : name.to_s
        insert[:uri] = opts.key?(:uri) ? opts[:uri] : name.to_s
        { success: true, runner_id: Legion::Data::Model::Runner.insert(insert) }
      end

      def update(runner_id:, **opts)
        runner = Legion::Data::Model::Runner[runner_id]
        update = {}
        %i[name namespace active queue uri].each do |column|
          next unless opts.key? column
          next if runner.values[column] == opts[column]

          update[column] = opts[column]
        end

        { success: true, changed: false, runner_id: runner_id } if update.count.zero?
        runner.update(update)
        { success: true, changed: true, updates: update, runner_id: runner_id }
      end

      def get(runner_id:, **_opts)
        Legion::Data::Model::Runner[runner_id].values
      end

      def delete(runner_id:, **_opts)
        { runner_id: runner_id, result: Legion::Data::Model::Runner[runner_id].delete }
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lex-lex-0.1.0 lib/legion/extensions/lex/runners/runner.rb