After a task has been completed, the worker calls the post_work method. This method allows the user to perform an operation after each task is completed. You can use it to close an APM transaction or to send a metric.
defpost_work(self,task,success,exception,):self.my_logger.debug(f'stopped working on {task.kwargs["url"]}: {time.time()}, exception: {exception}')ifexceptionisnotNone:self.apm_client.capture_exception()self.apm_client.end_transaction(result='success'ifsuccesselse'failure',)