Repository: bimpression/sosw

Issue:
Labourer: get_max_labourer_duration
Implement me.
Should receive this information from AWS API probably with DescribeFunction and cache this data in the Ecology Manager

Discussion:

Patch:
diff --git a/sosw/managers/ecology.py b/sosw/managers/ecology.py
index dbe0fb5..14ff1e8 100644
--- a/sosw/managers/ecology.py
+++ b/sosw/managers/ecology.py
@@ -31,8 +31,7 @@ ECO_STATUSES = (
 
 
 class EcologyManager(Processor):
-    DEFAULT_CONFIG = {
-    }
+    DEFAULT_CONFIG = {}
 
     running_tasks = defaultdict(int)
     task_client: TaskManager = None  # Will be Circular import! Careful!
@@ -124,11 +123,10 @@ class EcologyManager(Processor):
     def get_max_labourer_duration(self, labourer: Labourer) -> int:
         """
         Maximum duration of `labourer` executions.
-        Should ask this from aws:lambda API, but at the moment use the hardcoded maximum.
-        # TODO implement me.
         """
 
-        return 900
+        resp = self.task_client.lambda_client.get_function_configuration(FunctionName=labourer.arn)
+        return resp['Timeout']
 
 
     # The task_client of EcologyManager is just a pointer. We skip recursive stats to avoid infinite loop.


Test patch:
diff --git a/sosw/managers/test/unit/test_ecology.py b/sosw/managers/test/unit/test_ecology.py
index 7637e2d..90f552f 100644
--- a/sosw/managers/test/unit/test_ecology.py
+++ b/sosw/managers/test/unit/test_ecology.py
@@ -109,3 +109,10 @@ class ecology_manager_UnitTestCase(unittest.TestCase):
         # But the counter of tasks in cache should have.
         self.assertEqual(self.manager.running_tasks[self.LABOURER.id],
                          tm.get_count_of_running_tasks_for_labourer.return_value + 1 + 5)
+
+
+    def test_get_max_labourer_duration(self):
+        self.manager.task_client = MagicMock()
+        self.manager.task_client.lambda_client.get_function_configuration.return_value = {'Timeout': 300}
+
+        self.assertEqual(self.manager.get_max_labourer_duration(self.LABOURER), 300)