Warning, /swf-common-lib/README.md is written in an unsupported language. File is not indexed.
0001 # swf-common-lib
0002
0003 Common libraries and utilities for the swf-testbed ePIC streaming workflow testbed project.
0004
0005 ## Overview
0006
0007 This library provides shared functionality for SWF agents, including logging utilities and REST API
0008 integration for the swf-monitor service. Also included are utility classes wrapping MQ and Rucio communications.
0009
0010 ## Installation
0011
0012 ```bash
0013 pip install swf-common-lib
0014 ```
0015
0016 For development:
0017 ```bash
0018 pip install -e /path/to/swf-common-lib
0019 ```
0020
0021 ## Components
0022
0023 ### REST Logging (`swf_common_lib.rest_logging`)
0024
0025 A simple logging module that allows agents to send logs to the swf-monitor database via REST API using standard Python logging.
0026
0027 #### Quick Start
0028
0029 ```python
0030 import logging
0031 from swf_common_lib.rest_logging import setup_rest_logging
0032
0033 # Setup logging - this is all you need!
0034 logger = setup_rest_logging(
0035 app_name='my_agent',
0036 instance_name='agent_001'
0037 )
0038
0039 # Now just use standard Python logging
0040 logger.info("Agent starting up")
0041 logger.warning("Something needs attention")
0042 logger.error("An error occurred")
0043 ```
0044
0045 #### Features
0046
0047 - **Simple Setup**: Single function call to configure REST logging
0048 - **Fallback Support**: Automatically falls back to console logging if monitor is unavailable
0049 - **Standard Interface**: Uses Python's standard logging module
0050 - **Configurable**: Supports custom timeouts and monitor URLs
0051 - **Error Handling**: Graceful degradation when network issues occur
0052
0053 #### API Reference
0054
0055 **`setup_rest_logging(app_name, instance_name, base_url='http://localhost:8000', timeout=10)`**
0056
0057 Sets up REST logging for an agent.
0058
0059 **Parameters:**
0060 - `app_name` (str): Name of your application/agent
0061 - `instance_name` (str): Unique identifier for this instance
0062 - `base_url` (str): URL of swf-monitor service (default: 'http://localhost:8000')
0063 - `timeout` (int): Timeout in seconds for REST requests (default: 10)
0064
0065 **Returns:**
0066 - Configured logger ready to use
0067
0068 **Example with custom configuration:**
0069 ```python
0070 logger = setup_rest_logging(
0071 app_name='processing_agent',
0072 instance_name='proc_001',
0073 base_url='https://monitor.example.com',
0074 timeout=10
0075 )
0076 ```
0077
0078 #### Behavior
0079
0080 When the monitor service is available, logs are sent to the database via REST API. When unavailable:
0081
0082 1. Shows a warning message on first failure
0083 2. Falls back to standard console logging
0084 3. Continues working normally for the application
0085
0086 ### Logging Utils (`swf_common_lib.logging_utils`)
0087
0088 Traditional logging utilities for PostgreSQL database integration.
0089
0090 ## MQ and Rucio Utility packages
0091
0092 The *mq_comms* and *rucio_comms* packages provide convenient encapsulation of interactions
0093 with the ActiveMQ and Rucio systems, respectively. Each folder contains it's own README file
0094 with more details.