Sha256: 5cbc9c807dfa26afa1ea100fa44326dc1e67a39d6e840f4c5b3c053a41933487

Contents?: true

Size: 1.46 KB

Versions: 1

Compression:

Stored size: 1.46 KB

Contents

module MistralClient
  class Workflow < Base
    UNICODE_FIELDS = %w[definition input name project_id scope].freeze
    BOOL_FIELDS = [].freeze
    JSON_FIELDS = [].freeze

    PATH = 'workflows'.freeze

    include MistralClient::Mixins::MistralObject
    include MistralClient::Mixins::Definable
    include MistralClient::Mixins::Deletable

    def initialize(server, definition = nil, id: nil, name: nil)
      super()
      @server = server
      if definition
        @definition = parse_definition(definition)
        create_workflow
      elsif id || name
        @id = id || name
        reload
      end
    end

    def execute!(env: nil, task_name: nil, input: nil)
      Execution.new(@server,
                    workflow_id: @id,
                    env: env,
                    task_name: task_name,
                    input: input)
    end

    def valid?(definition)
      resp = perform_validation(definition)
      resp['valid']
    end

    def validate(definition)
      resp = perform_validation(definition)
      resp['error']&.split("\n")&.first
    end

    private

    def create_workflow
      resp = @server.post(PATH, @definition)
      if resp['workflows'].length > 1
        raise ConfigurationError,
              'Only one workflow per definition is supported'
      end
      ivars_from_response(resp['workflows'][0])
    end

    def perform_validation(definition)
      @server.post("#{PATH}/validate", parse_definition(definition))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mistral_client-2.0.0 lib/mistral_client/workflow.rb