Reputation: 1193
I have to methods with exactly the same logic. The only difference is that it returns different values.
async def job_pooling(self):
message['status'] = Text.NEW.value
await self.db.store_alert(..)
await self.aws.delete_message(..)
yield message
async def job_pooling(self):
message['status'] = Comment.NEW.value
store_message = await self.db.store_comment(..)
await self.aws.delete_message(..)
yield store_message
How to generalize it?
Upvotes: 1
Views: 2506
Reputation: 39546
Well, if you know type of store_item
result, you can use it instead of comparing to None
:
async def job_pooling(sqs_in, status, store_item, delete_message):
message['status'] = status.NEW.value
item = await store_item(message)
await delete_message(message=message, sqs_url=sqs_in)
if isinstance(item, dict):
yield item
yield message
Upvotes: 1