Last active
April 18, 2019 15:54
-
-
Save danish1010/feb1da638f60fa5f38285c9307270a7a to your computer and use it in GitHub Desktop.
RUNNING Datadog in GAE
This file contains hidden or 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
def get_request_from_user(): | |
payload = { | |
metric_name: 'xyz', | |
value: 1 | |
} | |
# Add payload to the queue | |
# which would we picked up by the worker to flush metric | |
add_job_to_metrics_flush_worker(payload) | |
# return something back to the user |
This file contains hidden or 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
# using https://github.com/DataDog/datadogpy | |
""" | |
This complete file runs on a backend-worker or | |
i am a job is added in the queue and the worker executes the | |
function worker_job | |
""" | |
stats = None | |
def initialize(): | |
global stats | |
datadog.initialize(**options) | |
stats = datadog.ThreadStats() | |
# GAE do not allow creation of a new thread | |
# hence flush_in_thread = False | |
stats.start(flush_in_thread=False) | |
def worker_job(metric_name, value): | |
stats.increment(metric_name, value) | |
# Given we dont have any thread to flush | |
# we do it here | |
stats.flush() | |
initialize() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment