def handle_delete(self, ch, method, properties, body): logger.info(f"Handling comment.delete. {body}") try: body = json.loads(body)['body'] thread_id = body['thread_id'] thread_cache_key = Thread.make_cache_key(thread_id) cache.incr_field(thread_cache_key, 'num_comments', -1) # Acknowledgement ch.basic_ack(delivery_tag=method.delivery_tag) logger.info("Finished updating number of comments in cache.") except json.JSONDecodeError as ex: logger.warning("Error while decoding json:", str(ex))
def handle_update(self, ch, method, props, body): logger.info("Vote updated; atomically updating scores.") try: body = json.loads(body)['body'] post_id = body['voted_thread_id'] user_id = body['voter_id'] direction = body['direction'] except json.JSONDecodeError as ex: logger.info("Error while decoding json:", str(ex)) thread_key = Thread.make_cache_key(post_id) return cache.incr_field(thread_key, 'score', direction * -1 * 2)