initial commit
This commit is contained in:
@@ -0,0 +1,69 @@
|
||||
import flask
|
||||
import huey
|
||||
import sentry_sdk
|
||||
import sentry_sdk.integrations.flask
|
||||
from huey import signals
|
||||
|
||||
sentry_sdk.init(
|
||||
"https://379e370d4dee471b8ca5c7884d2137c0@o271257.ingest.sentry.io/6214795",
|
||||
# Set traces_sample_rate to 1.0 to capture 100%
|
||||
# of transactions for performance monitoring.
|
||||
# We recommend adjusting this value in production.
|
||||
traces_sample_rate=1.0,
|
||||
with_locals=True,
|
||||
max_breadcrumbs=100,
|
||||
integrations=[sentry_sdk.integrations.flask.FlaskIntegration()],
|
||||
)
|
||||
|
||||
worker = huey.SqliteHuey(filename='worker.sqlite3')
|
||||
|
||||
|
||||
@worker.signal(signals.SIGNAL_EXECUTING, signals.SIGNAL_LOCKED, signals.SIGNAL_CANCELED, signals.SIGNAL_REVOKED)
|
||||
def task_executing_handler(signal: str, task: huey.api.Task):
|
||||
sentry_sdk.add_breadcrumb(
|
||||
category='worker',
|
||||
data=dict(
|
||||
signal=signal,
|
||||
task_id=task.id,
|
||||
task_name=task.name,
|
||||
task_retries=task.retries,
|
||||
task_args=task.args,
|
||||
task_kwargs=task.kwargs,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
@worker.signal(signals.SIGNAL_ERROR)
|
||||
def task_not_executed_handler(signal: str, task: huey.api.Task, exc: Exception):
|
||||
with sentry_sdk.push_scope():
|
||||
sentry_sdk.capture_exception(exc)
|
||||
|
||||
|
||||
class SomeService:
|
||||
@classmethod
|
||||
@worker.task()
|
||||
def do_something(cls, *args, **kwargs):
|
||||
print(args, kwargs)
|
||||
|
||||
@classmethod
|
||||
@worker.task()
|
||||
def fail_something(cls, *args, **kwargs):
|
||||
raise Exception('boom')
|
||||
|
||||
def do(self):
|
||||
self.do_something(2, a=1)
|
||||
|
||||
def fail(self):
|
||||
self.fail_something(2, a=1)
|
||||
|
||||
|
||||
def test_request():
|
||||
flask_app = flask.Flask(__name__)
|
||||
|
||||
@flask_app.post('/')
|
||||
def fail():
|
||||
SomeService().fail()
|
||||
return {'a': 5}
|
||||
|
||||
flask_app.add_url_rule('/', 'home', fail)
|
||||
flask_app.test_client().post('/', json={'a': 10})
|
||||
Reference in New Issue
Block a user