Sha256: 3eba32a9d260d44ff057c3464c01bbf3c5ed498256487c87a8e2b480f0b49cb9

Contents?: true

Size: 1.34 KB

Versions: 1

Compression:

Stored size: 1.34 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)
      @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)
      Execution.new(@server, workflow_id: @id, env: env, task_name: task_name)
    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-1.0.0 lib/mistral_client/workflow.rb