spinetoolbox.server.engine_client
Client for exchanging messages between the toolbox and the Spine Engine Server.
Module Contents
Classes
Generic enumeration. |
|
|
- class spinetoolbox.server.engine_client.ClientSecurityModel[source]
Bases:
enum.Enum
Generic enumeration.
Derive from this class to define new enumerations.
- class spinetoolbox.server.engine_client.EngineClient(host, port, sec_model, sec_folder, ping=True)[source]
- Parameters
host (str) – IP address of the Spine Engine Server
port (int) – Port of the client facing (frontend) socket on Spine Engine Server
sec_model (ClientSecurityModel) – Client security scheme
sec_folder (str) – Path to security file directory
ping (bool) – Whether to check connectivity at instance creation
- connect_pull_socket(port)[source]
Connects a PULL socket for receiving engine execution events and files from server.
- Parameters
port (str) – Port of the PUSH socket on server
- rcv_next(dealer_or_pull)[source]
Polls all sockets and returns a new reply based on given socket ‘name’.
- Parameters
dealer_or_pull (str) – “dealer” to wait reply from DEALER socket, “pull” to wait reply from PULL socket
- _check_connectivity(timeout)[source]
Pings server, waits for the response, and acts accordingly.
- Parameters
timeout (int) – Time to wait for a response before giving up [ms]
- Returns
void
- Raises
RemoteEngineInitFailed if the server is not responding. –
- set_start_time()[source]
Sets a start time for an operation. Call get_elapsed_time() after an operation has finished to get the elapsed time string.
- upload_project(project_dir_name, fpath)[source]
Uploads the zipped project file to server. Project zip file must be ready and the server available before calling this method.
- Parameters
project_dir_name (str) – Project directory name
fpath (str) – Absolute path to zipped project file.
- Returns
Project execution job Id
- Return type
str
- start_execution(engine_data, job_id)[source]
Sends the start execution request along with job Id and engine (dag) data to the server. Response message data contains the push/pull socket port if execution starts successfully.
- Parameters
engine_data (str) – Input for SpineEngine as JSON str. Includes most of project.json, settings, etc.
job_id (str) – Project execution job Id on server
- Returns
Response tuple (event_type, data). Event_type is “server_init_failed”, “remote_execution_init_failed” or “remote_execution_started. data is an error message or the publish and push sockets ports concatenated with ‘:’.
- Return type
tuple
- stop_execution(job_id)[source]
Sends a request to stop executing the DAG that is managed by this client.
- Parameters
job_id (str) – Job Id on server to stop
- answer_prompt(job_id, prompter_id, answer)[source]
Sends a request to answer a prompt from the DAG that is managed by this client.
- Parameters
job_id (str) – Job Id on server to stop
prompter_id (int) –
answer –
- save_downloaded_file(b_rel_path, file_data)[source]
Saves downloaded file to project directory.
- Parameters
b_rel_path (bytes) – Relative path (to project dir) where the file should be saved
file_data (bytes) – File as bytes object
- retrieve_project(job_id)[source]
Retrieves a zipped project file from server.
- Parameters
job_id (str) – Job Id for finding the project directory on server
- Returns
Zipped project file
- Return type
bytes
- remove_project_from_server(job_id)[source]
Sends a request to remove a project directory from server.
- Parameters
job_id (str) – Job Id for finding the project directory on server
- Returns
Message from server
- Return type
str
- send_is_complete(persistent_key, cmd)[source]
Sends a request to process is_complete(cmd) in persistent manager on server and returns the response.
- send_issue_persistent_command(persistent_key, cmd)[source]
Sends a request to process given command in persistent manager identified by given key. Yields the response string(s) as they arrive from server.
- send_get_persistent_completions(persistent_key, text)[source]
Requests completions to given text from persistent execution backend.
- send_get_persistent_history_item(persistent_key, text, prefix, backwards)[source]
Requests the former or latter history item from persistent execution backend.
- send_restart_persistent(persistent_key)[source]
Sends restart persistent cmd to persistent execution manager backend on server. Yields the messages resulting from this operation to persistent console client.
- send_interrupt_persistent(persistent_key)[source]
Sends interrupt persistent cmd to persistent execution manager backend on server.
- send_kill_persistent(persistent_key)[source]
Sends kill persistent cmd to persistent execution manager backend on server.
- Parameters
persistent_key (tuple) – persistent manager identifier
- send_request_to_persistent(data)[source]
Sends given data containing persistent_key, command, cmd_to_persistent to Spine Engine Server to be processed by a persistent execution manager backend. Makes a request using REQ socket, parses the response into a ServerMessage, and returns the second part of the data field.
- send_request_to_persistent_generator(data)[source]
Pulls all messages from server, that were the result of sending given data to Spine Engine Server.