EcologyManager

View Licence Agreement

class sosw.managers.ecology.EcologyManager(*args, **kwargs)[source]
add_running_tasks_for_labourer(labourer: Labourer, count: int = 1)[source]

Adds to the current counter of running tasks the given count. Invokes the getter first in case the original number was not yet calculated from DynamoDB.

count_running_tasks_for_labourer(labourer: Labourer) int[source]

TODO Refactor this to cache the value in the Labourer object itself. Should also update add_running_tasks_for_labourer() for that.

fetch_metric_stats(metric: Dict) List[Dict][source]

Fetches from CloudWatch Datapoints of aggregated metric statistics. Fields in metric are the attributes of get_metric_statistics. Additional parameter: MetricAggregationTimeSlice in seconds is used to calculate the Start and EndTime.

If some fields are missing in the metric, the defaults come from config['default_metric_values']

get_health(value: int | float, metric: Dict) int[source]

Checks the value against the health_metric configuration.

get_labourer_average_duration(labourer: Labourer) int[source]

Calculates the average duration of labourer executions.

The operation consumes DynamoDB RCU . Normally this method is called for each labourer only once during registration of Labourers. If you want to learn this value, you should ask Labourer object.

get_labourer_status(labourer: Labourer) int[source]

Get the worst (lowest) health status according to preconfigured health metrics of the Labourer.

Current ECO_STATUSES:

  • (0, ‘Bad’)

  • (1, ‘Poor’)

  • (2, ‘Moderate’)

  • (3, ‘Good’)

  • (4, ‘High’)

get_max_labourer_duration(labourer: Labourer) int[source]

Maximum duration of labourer executions.

get_stats(recursive=False)[source]

Return statistics of operations performed by current instance of the Class.

Statistics of custom clients existing in the Processor is also aggregated by default. Clients must be initialized as self.some_client ending with _client suffix (e.g. self.dynamo_db_client). Clients must also have their own get_stats() methods implemented.

Be careful about circular get_stats() calls from child classes. If required overwrite get_stats() with recursive = False.

Parameters:

recursive – Merge stats from self.***_client.

Return type:

dict

Returns:

Statistics counter of current Processor instance.

register_task_manager(task_manager: TaskManager)[source]

We will have to make some queries, and don’t want to initialise another TaskManager locally. Just receive the pointer to TaskManager from whoever needs.

This could be in __init__, but I don’t want to update the initialization workflows for every function initialising me. They usually use built-in in core Processor mechanism to register_clients().

reset_stats(recursive=False)[source]

Cleans statistics other than specified for the lifetime of processor. All the parameters with prefix ‘total_’ are also preserved.

The function makes sense if your Processor lives outside the scope of lambda_handler.

Be careful about circular get_stats() calls from child classes. If required overwrite reset_stats() with recursive = False.

Parameters:

recursive – Reset stats from self.***_client.