class Zenaton::Services::GraphQL::Client

Small client to interact with Zenaton's GraphQL API

Constants

ZENATON_GATEWAY_URL

Public Class Methods

new(http:) click to toggle source

Setup the GraphQL client with the HTTP client to use

# File lib/zenaton/services/graph_ql/client.rb, line 23
def initialize(http:)
  @http = http
end

Public Instance Methods

find_workflow(name, custom_id, credentials) click to toggle source

Search for a workflow with a custom ID

# File lib/zenaton/services/graph_ql/client.rb, line 84
def find_workflow(name, custom_id, credentials)
  app_env = credentials['app_env']
  query = WorkflowQuery.new(name, custom_id, app_env)
  execute(query, credentials)
end
kill_workflow(name, custom_id, credentials) click to toggle source

Stopping an existing workflow

# File lib/zenaton/services/graph_ql/client.rb, line 56
def kill_workflow(name, custom_id, credentials)
  app_env = credentials['app_env']
  mutation = KillWorkflowMutation.new(name, custom_id, app_env)
  execute(mutation, credentials)
end
pause_workflow(name, custom_id, credentials) click to toggle source

Pausing an existing workflow

# File lib/zenaton/services/graph_ql/client.rb, line 63
def pause_workflow(name, custom_id, credentials)
  app_env = credentials['app_env']
  mutation = PauseWorkflowMutation.new(name, custom_id, app_env)
  execute(mutation, credentials)
end
resume_workflow(name, custom_id, credentials) click to toggle source

Resuming a paused workflow

# File lib/zenaton/services/graph_ql/client.rb, line 70
def resume_workflow(name, custom_id, credentials)
  app_env = credentials['app_env']
  mutation = ResumeWorkflowMutation.new(name, custom_id, app_env)
  execute(mutation, credentials)
end
schedule_task(task, cron, credentials) click to toggle source

Scheduling a task

# File lib/zenaton/services/graph_ql/client.rb, line 35
def schedule_task(task, cron, credentials)
  app_env = credentials['app_env']
  mutation = CreateTaskScheduleMutation.new(task, cron, app_env)
  execute(mutation, credentials)
end
schedule_workflow(workflow, cron, credentials) click to toggle source

Scheduling a workflow

# File lib/zenaton/services/graph_ql/client.rb, line 28
def schedule_workflow(workflow, cron, credentials)
  app_env = credentials['app_env']
  mutation = CreateWorkflowScheduleMutation.new(workflow, cron, app_env)
  execute(mutation, credentials)
end
send_event(name, custom_id, event, credentials) click to toggle source

Sending an event to an existing workflow

# File lib/zenaton/services/graph_ql/client.rb, line 77
def send_event(name, custom_id, event, credentials)
  app_env = credentials['app_env']
  mutation = SendEventMutation.new(name, custom_id, event, app_env)
  execute(mutation, credentials)
end
start_task(task, credentials) click to toggle source

Dispatching a single task

# File lib/zenaton/services/graph_ql/client.rb, line 42
def start_task(task, credentials)
  app_env = credentials['app_env']
  mutation = DispatchTaskMutation.new(task, app_env)
  execute(mutation, credentials)
end
start_workflow(workflow, credentials) click to toggle source

Dispatching a workflow

# File lib/zenaton/services/graph_ql/client.rb, line 49
def start_workflow(workflow, credentials)
  app_env = credentials['app_env']
  mutation = DispatchWorkflowMutation.new(workflow, app_env)
  execute(mutation, credentials)
end

Private Instance Methods

execute(operation, credentials) click to toggle source
# File lib/zenaton/services/graph_ql/client.rb, line 103
def execute(operation, credentials)
  response = @http.post(url, operation.body, headers(credentials))
  operation.result(response)
end
headers(credentials) click to toggle source
# File lib/zenaton/services/graph_ql/client.rb, line 96
def headers(credentials)
  {
    'app-id' => credentials['app_id'],
    'api-token' => credentials['api_token']
  }
end
url() click to toggle source
# File lib/zenaton/services/graph_ql/client.rb, line 92
def url
  ENV['ZENATON_GATEWAY_URL'] || ZENATON_GATEWAY_URL
end