def test_move_task_to_retry_table(self): _ = self.manager.get_db_field_name labourer_id = 'lambda1' task = { _('task_id'): '123', _('labourer_id'): labourer_id, _('greenfield'): 8888, _('attempts'): 2 } delay = 300 self.dynamo_client.put(task) self.manager.move_task_to_retry_table(task, delay) result_tasks = self.dynamo_client.get_by_query({_('task_id'): '123'}) self.assertEqual(len(result_tasks), 0) result_retry_tasks = self.dynamo_client.get_by_query( {_('labourer_id'): labourer_id}, table_name=self.retry_tasks_table) self.assertEqual(len(result_retry_tasks), 1) result = first_or_none(result_retry_tasks) for k in task: self.assertEqual(task[k], result[k]) for k in result: if k != _('desired_launch_time'): self.assertEqual(result[k], task[k]) self.assertTrue( time.time() + delay - 60 < result[_('desired_launch_time')] < time.time() + delay + 60)
def get_labourer(self, labourer_id: str) -> Labourer: return first_or_none(self.get_labourers(), lambda x: x.id == labourer_id)