Module worker

Module worker 

Source
Expand description

Workers for asset data collection and information updates.

This module defines traits and implementations for workers that monitor and update asset information. Workers are responsible for collecting data from various sources and updating asset information in the store.

The module provides:

  • The AssetWorker trait which defines the common interface for all asset workers
  • Specialized worker implementations for different protocols and data sources
  • Error handling specific to asset workers

§Worker Types

The module includes various worker implementations:

  • REST-based workers in the rest module for HTTP/HTTPS API polling
  • WebSocket-based workers in the websocket module for real-time data streaming

§Worker Lifecycle

Workers follow a typical lifecycle pattern:

  1. Initialization: Workers are built using their build method and configured with options
  2. Running: Workers run continuously, collecting data from sources and updating the store
  3. Error Handling: Workers should handle temporary failures gracefully with retries
  4. Shutdown: Workers should support graceful shutdown when requested

§Worker Storage

Workers should use the WorkerStore wrapper to interact with the main store. This wrapper provides namespace isolation for each worker, ensuring that different workers can operate without conflicts. Each worker should use the WorkerStore to update asset information through the set_asset_info and set_batch_asset_info methods.

§Extensibility

While this module provides general-purpose implementations that cover common use cases, the AssetWorker trait is designed for extensibility. Users can create custom worker implementations by implementing this trait to support specialized data sources, protocols, or business logic beyond what’s provided in the standard implementations.

§Implementation

When implementing a new worker type:

  1. Implement the AssetWorker trait
  2. Define appropriate configuration options via the associated Opts type
  3. Implement the build method to create worker instances from configuration
  4. Implement any protocol-specific functionality in the worker
  5. Use WorkerStore to store asset information

Workers are typically registered with a worker registry and managed by the system to handle data collection and updates in a coordinated way.

Modules§

error
This module provides error handling functionality for asset workers. It defines a custom error type that can wrap other errors and provide additional context.
rest
REST-based asset information providers and polling mechanisms.
websocket
WebSocket-based asset information providers and streaming mechanisms.

Traits§

AssetWorker
The universal trait for all workers that collect and update asset info.