Created
December 18, 2012 20:22
-
-
Save anonymous/4331602 to your computer and use it in GitHub Desktop.
example metrics worker in Python using pynsq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import nsq | |
import json | |
def metrics_write(message): | |
json_data = json.loads(message) | |
# iterate over the metrics you want to record and write | |
# into your downstream metrics system | |
if any_metrics_failed: | |
# this will indicate to pynsq that it should re-queue | |
# the message for you | |
return False | |
return True | |
tasks = {"metrics_write": metrics_write} | |
r = nsq.Reader(tasks, nsqd_tcp_addresses=['127.0.0.1:4150'], | |
topic="api_requests", channel="metrics") | |
nsq.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment