class Beetle::Server
- Beetle::Server
- Reference
- Object
Overview
The Server class is the co-ordinator of the Beetle
subsystem.
The basic process is:
- Create an instance of the
Server
class - Optionally create an archiver and register it to your server
- Register all your individual
Task
subclasses that actually do the work you want to measure - Run the
#listen
method to 'wait for instructions'.
The server listens on the following endpoints:
/job
- Accept a json payload representing a newJob
. This doesn't actually run the job. Rather it saves it to be run by the/exec
request./exec
- Execute a previously saved job. Only one job execution can be in progress at any point in time. If you submit a/exec
request while another is still in progress, it will be rejected./tasks
- Return a list of registeredTask
subclasses that may be used in aJob
definition./jobs
- Return a list of saved jobs./status
- Return a JSON encodedServerStatus
object showing the current server state./quit
- Stop listening
Defined in:
beetle/server.crConstructors
Instance Method Summary
-
#archiver=(archiver : Archiver)
Set the optional archiver to be run on completion of a job execution.
-
#listen
Listen for instructions.
- #register_task(task_class : Task.class)
Constructor Detail
Instance Method Detail
Set the optional archiver to be run on completion of a job execution.
def listen
#
Listen for instructions. The endpoints are described above. The payloads are:
/job
- A JSON representation of aJob
. For example:
{
"name": "charges_local",
"host": "http://localhost:3001",
"run_for_sec": 10,
"tasks": [
{
"task_class": "BCaaS::ChargeTask",
"weight": 1,
"sleep_min_msec": 500,
"sleep_max_msec": 1000
}
]
}
If the request is valid, the job will be stored and available to be
run with the /exec
request. The response body will simply be Job saved
.
/exec
- A JSON representation of anExec
object. For example:
{
"name": "charges_local",
"params": {
"sc_mc": "mc"
}
}
A valid request will result in the named job being executed synchronously. On
completion the response body will contain a JSON representation of a JobExec
object. For example:
{
"id": "77f2d06c-be37-4bdc-98ad-02fed5acd892",
"name": "charges_local_2",
"host": "http://localhost:3001",
"t_start": "2019-02-19 21:36:47.430+00:00",
"elapsed_usec": 750782,
"params": {
"sc_mc": "mc"
},
"error_400_on_threshold_exceeded": false,
"tasks": {
"BCaaS::ChargeTask": {
"host": "http://localhost:3001",
"weight": 1,
"sleep_min_msec": 500,
"sleep_max_msec": 1000,
"threshold_avg_usec": 0,
"threshold_max_usec": 0,
"n_task": 2,
"n_success": 2,
"n_fail": 0,
"min_usec": 448,
"max_usec": 1980,
"avg_usec": 1214,
"tot_usec": 2428,
"executions": [
{
"id": "80b65420-2902-4e44-8676-6e2f620003af",
"swarm_id": 1,
"t_start": "2019-02-19 21:36:47.430+00:00",
"elapsed_usec": 1980,
"request_context": "buyer_id: 5066112c-b321-40a0-ac61-a7868b1921ee",
"is_success": true
},
{
"id": "5f173b79-9e11-423b-9fe9-e204c669af3a",
"swarm_id": 1,
"t_start": "2019-02-19 21:36:48.180+00:00",
"elapsed_usec": 448,
"request_context": "buyer_id: 45672a98-281a-4ee3-857a-89ea27fa2dcb",
"is_success": true
}
],
"threshold_avg_exceeded": false,
"threshold_max_exceeded": false
}
},
"run_for_sec": 0,
"run_n": 2,
"n_swarm": 1,
"threshold_exceeded": false
}
/tasks
This endpoint doesn't require a payload. It returns a JSON representation of the list of registered (viaServer#register_task
) tasks. For example:
{
"tasks": [
"BCaaS::ChargeTask",
"BCaaS::PreAuthTask"
]
}
/jobs
This endpoint doesn't require a payload. It returns a JSON representation of all the jobs available for execution (via the/exec
endpoint). For example:
{
"charges_local_2": {
"name": "charges_local_2",
"host": "http://localhost:3001",
"tasks": [
{
"task_class": "BCaaS::ChargeTask",
"weight": 1,
"sleep_min_msec": 500,
"sleep_max_msec": 1000,
"threshold_avg_usec": 0,
"threshold_max_usec": 0,
"host": "http://localhost:3001"
}
],
"run_for_sec": 0,
"run_n": 2,
"n_swarm": 1
},
"charges_staging": {
"name": "charges_staging",
"tasks": [
{
"task_class": "BCaaS::ChargeTask",
"weight": 1,
"sleep_min_msec": 500,
"sleep_max_msec": 1000,
"threshold_avg_usec": 0,
"threshold_max_usec": 0,
"host": "https://app.bcaas-staging.msts.com/api/v20180807"
}
],
"run_for_sec": 10,
"run_n": 0,
"n_swarm": 1
},
"charges_5_staging": {
"name": "charges_5_staging",
"tasks": [
{
"task_class": "BCaaS::ChargeTask",
"weight": 1,
"sleep_min_msec": 0,
"sleep_max_msec": 0,
"threshold_avg_usec": 0,
"threshold_max_usec": 0,
"host": "https://app.bcaas-staging.msts.com/api/v20180807"
}
],
"run_for_sec": 10,
"run_n": 0,
"n_swarm": 5
}
}
/quit
- Terminate the server. No payload is required.