class Zenaton::Client
Constants
- APP_ENV
- APP_ID
- DEFAULT_WORKER_PORT
- WORKER_API_VERSION
- ZENATON_WORKER_URL
Attributes
Public Class Methods
Class
method that sets the three tokens needed to interact with the API @param app_id
[String] the ID of your Zenaton
application @param api_token
[String] your Zenaton
account API token @param app_env
[String] the environment (dev, staging, prod) to run under @return [Zenaton::Client] the instance of the client.
# File lib/zenaton/client.rb, line 28 def self.init(app_id, api_token, app_env) instance.tap do |client| client.app_id = app_id client.api_token = api_token client.app_env = app_env end end
@private
# File lib/zenaton/client.rb, line 37 def initialize @http = Services::Http.new @graphql = Services::GraphQL::Client.new(http: @http) @serializer = Services::Serializer.new @properties = Services::Properties.new end
Public Instance Methods
Finds a workflow @param workflow_name [String] the class name of the workflow @param custom_id [String] the custom ID of the workflow @return [Zenaton::Interfaces::Workflow, nil]
# File lib/zenaton/client.rb, line 112 def find_workflow(workflow_name, custom_id) @graphql.find_workflow(workflow_name, custom_id, credentials) end
Stops a workflow @param name [String] the class name of the workflow @param custom_id [String] the custom ID of the workflow @return [NilClass]
# File lib/zenaton/client.rb, line 88 def kill_workflow(name, custom_id) @graphql.kill_workflow(name, custom_id, credentials) end
Pauses a workflow @param name [String] the class name of the workflow @param custom_id [String] the custom ID of the workflow @return [NilClass]
# File lib/zenaton/client.rb, line 96 def pause_workflow(name, custom_id) @graphql.pause_workflow(name, custom_id, credentials) end
Resumes a workflow @param name [String] the class name of the workflow @param custom_id [String] the custom ID of the workflow @return [NilClass]
# File lib/zenaton/client.rb, line 104 def resume_workflow(name, custom_id) @graphql.resume_workflow(name, custom_id, credentials) end
Sends an event to a workflow @param workflow_name [String] the class name of the workflow @param custom_id [String] the custom ID of the workflow @param event [Zenaton::Interfaces::Event] the event to send @return [NilClass]
# File lib/zenaton/client.rb, line 121 def send_event(workflow_name, custom_id, event) @graphql.send_event(workflow_name, custom_id, event, credentials) end
Schedule a task for repeated execution
# File lib/zenaton/client.rb, line 73 def start_scheduled_task(task, cron) res = @graphql.schedule_task(task, cron, credentials) res && res['createTaskSchedule'] end
Schedule a workflow for repeated execution
# File lib/zenaton/client.rb, line 79 def start_scheduled_workflow(flow, cron) res = @graphql.schedule_workflow(flow, cron, credentials) res && res['createWorkflowSchedule'] end
Start a single task @param task [Zenaton::Interfaces::Task]
# File lib/zenaton/client.rb, line 62 def start_task(task) @graphql.start_task(task, credentials) end
Start the specified workflow @param flow [Zenaton::Interfaces::Workflow]
# File lib/zenaton/client.rb, line 68 def start_workflow(flow) @graphql.start_workflow(flow, credentials) end
Gets the url for the workers @param resource [String] the endpoint for the worker @param params [Hash|String] query params to be url encoded @return [String] the workers url with parameters
# File lib/zenaton/client.rb, line 48 def worker_url(resource = '', params = {}) base_url = ENV['ZENATON_WORKER_URL'] || ZENATON_WORKER_URL port = ENV['ZENATON_WORKER_PORT'] || DEFAULT_WORKER_PORT url = "#{base_url}:#{port}/api/#{WORKER_API_VERSION}/#{resource}" if params.is_a?(Hash) append_params_to_url(url, params) else add_app_env("#{url}?", params) end end
Private Instance Methods
DEPRECATED: This implementation does not safely encode the parameters to be passed as query params in a get request. This method gets called by agents up to version 0.4.5
# File lib/zenaton/client.rb, line 138 def add_app_env(url, params) deprecation_warning = <<~WARN [WARNING] You are running a Zenaton agent with a version <= 0.4.5 Please consider upgrading to a more recent version. WARN warn(deprecation_warning) app_env = @app_env ? "#{APP_ENV}=#{@app_env}&" : '' app_id = @app_id ? "#{APP_ID}=#{@app_id}&" : '' "#{url}#{app_env}#{app_id}#{params}" end
# File lib/zenaton/client.rb, line 151 def append_params_to_url(url, params) params[APP_ENV] = @app_env if @app_env params[APP_ID] = @app_id if @app_id "#{url}?#{URI.encode_www_form(params)}" end
# File lib/zenaton/client.rb, line 127 def credentials { 'app_id' => @app_id, 'api_token' => @api_token, 'app_env' => @app_env } end