CloudReactor Ruby API client and Wrapper I/O
Overview
This Ruby gem consists of 2 parts:
-
The CloudReactor API client allows ruby applications to programmatically create, monitor, and manage Tasks and Workflows in CloudReactor. Most notably, you can start and stop Tasks and Workflows by creating Task Executions and Workflow Executions.
-
The Wrapper I/O module allows ruby applications to communicate with the CloudReactor process wrapper which is the parent process.
To install this gem, include:
gem 'cloudreactor_api_client'
in your Gemfile
.
See the CloudReactor landing page to see the benefits of monitoring and managing your tasks with CloudReactor.
API client
The API client allows your program to control various entities in CloudReactor, most notably, Tasks and Workflows. The code and documentation are generated by OpenAPI generator.
To start an existing Task, create a TaskExecution linked to the Task, with a
status of CloudReactorAPIClient::TaskExecutionStatus::MANUALLY_STARTED
:
config = CloudReactorAPIClient::Configuration.new
config.access_token = 'YOUR API KEY'
api_client = CloudReactorAPIClient::ApiClient.new(config)
task = CloudReactorAPIClient::NameAndUuid.new
task.name = 'Sample Task'
task_execution = CloudReactorAPIClient::TaskExecution.new
task_execution.task = task
task_execution.status = CloudReactorAPIClient::TaskExecutionStatus::MANUALLY_STARTED
te_api = CloudReactorAPIClient::TaskExecutionsApi.new(api_client)
te_api.task_executions_create(task_execution)
Wrapper I/O
While running a ruby process that is wrapped by a CloudReactor process wrapper,
you can use CloudReactorWrapperIO::StatusUpdater
to
send updates about your process to the wrapper. The wrapper will send those
updates to the CloudReactor API server during its next heartbeat.
Updates can include:
- success count
- error count
- skipped count
- expected count
- last status message
- any additional properties that can be serialized into JSON
Updates are communicated via a local UDP socket which means they are theoretically unreliable. However, in practice, updates are almost always picked up correctly.
Example usage
# This is necessary even in Rails, due to the module name not matching the
# package name.
require 'cloudreactor_wrapper_io'
# Use the environment variables
# PROC_WRAPPER_ENABLE_STATUS_UPDATE_LISTENER (set to TRUE or FALSE)
# PROC_WRAPPER_STATUS_UPDATE_SOCKET_PORT (set to an integer)
# to determine configuration. These environment variables are typically passed
# to the process wrapper which then passes them on to your process.
status_updater = CloudReactorWrapperIO::StatusUpdater.new()
begin
status_updater.send_update(
success_count: 1,
error_count: 2,
last_status_message: 'running'
)
ensure
status_updater.close()
end
More documentation
License
This project is covered by the BSD 2-clause license.