Search code examples
djangopython-3.xdjango-channels

Channel Worker crash: how to do some task before crash?


For debugging purposes, I need to do a task (send an email) when some Channel Workers stops for an error.

I don't find a closure method that I could edit to add mi task in the SyncConsumer or AsyncConsumer.

channels==2.2.0 channels-redis==2.4.0


Solution

  • For a completely generic approach:

    You can try overriding the Consumers __call__ method

    async def __call__(self, receive, send):
    
         try: 
             await super().__call__(receive, send):
         except:
             .... do your stuff
             raise