Created
November 23, 2013 00:14
Revisions
-
amjith created this gist
Nov 23, 2013 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,34 @@ import newrelic.agent newrelic.agent.initialize('staging.ini') newrelic.agent.register_application(timeout=10.0) def add(a, b): return a + b def sub(a, b): return a - b def mul(a, b): return a * b def div(a, b): return a / b class TaskRunner(object): def __init__(self): self.application = newrelic.agent.application() self.task_list = {'add': add, 'sub': sub, 'mul': mul, 'div': div} def run_task(self, name, args): task = self.task_list[name] name = newrelic.agent.callable_name(task) with newrelic.agent.BackgroundTask(self.application, name=name, group='Task'): return task(*args) t = TaskRunner() print t.run_task('add', (1, 2)) print t.run_task('sub', (1, 2)) print t.run_task('mul', (1, 2)) print t.run_task('div', (1, 2))