Skip to main content

Update Event Progress

Description

The update_event_progress function sends a PATCH request to update the progress of a specific event. It updates the event progress by sending the device name and the completion percentage to the web service. The function returns a WebServiceResult object that contains the response code, response string, and parsed JSON data if available.

Function Signature:

def update_event_progress(ws_config: WebServiceConfig, event_id: int, device_name: str, percent_complete: float) -> WebServiceResult:

Parameters

  • ws_config (WebServiceConfig): Configuration for the web service connection.
  • event_id (int): The ID of the event to update.
  • device_name (str): The name of the device updating the progress.
  • percent_complete (float): The completion percentage of the event.

Returns

  • WebServiceResult: A result object containing:
    • http_response_code: The response code from the web service.
    • http_response_string: The response string from the web service.
    • json_data: The parsed JSON response from the web service, or None if there was an error.
    • code: A status code (0 for success, -1 for failure).
    • description: A description of any error that occurred.

Example Usage

ws_config = WebServiceConfig(base_url="https://api.actionstreamer.com")
event_id = 123
device_name = "Device123"
percent_complete = 75.0
result = update_event_progress(ws_config, event_id, device_name, percent_complete)
print(result.http_response_code)
print(result.json_data)

Behavior

  • The function sends a PATCH request to the web service with the device_name and percent_complete as the payload to update the event's progress.
  • The response is parsed into a WebServiceResult object, which contains the response code, response string, and parsed JSON data.
  • If the response string is not empty, it attempts to parse the JSON response and include it in the result.
  • Any errors during the request or JSON processing are caught, and an exception description is added to the result.

Error Handling

  • General Exception: Any errors during the request or JSON processing will be caught, and the error description will be included in the result.
  • Exception Information: The function prints the filename and line number for easier debugging when an exception is encountered.