Merge lp:~james-w/python-oops-celery/docstrings into lp:python-oops-celery

Proposed by James Westby
Status: Merged
Approved by: James Westby
Approved revision: 7
Merged at revision: 5
Proposed branch: lp:~james-w/python-oops-celery/docstrings
Merge into: lp:python-oops-celery
Prerequisite: lp:~james-w/python-oops-celery/hooks-based
Diff against target: 63 lines (+35/-0)
1 file modified
oops_celery/oops_reporter.py (+35/-0)
To merge this branch: bzr merge lp:~james-w/python-oops-celery/docstrings
Reviewer Review Type Date Requested Status
Sidnei da Silva (community) Approve
Review via email: mp+90313@code.launchpad.net

Commit message

Add some docstrings to the code.

Description of the change

Hi,

Correcting the lack of docstrings for those who wish to read them
rather than the code.

Thanks,

James

To post a comment you must log in.
7. By James Westby

Merged hooks-based into docstrings.

Revision history for this message
Sidnei da Silva (sidnei) wrote :

Oh, I was getting used to the lack of them. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'oops_celery/oops_reporter.py'
2--- oops_celery/oops_reporter.py 2012-01-26 19:16:49 +0000
3+++ oops_celery/oops_reporter.py 2012-01-26 19:16:49 +0000
4@@ -2,17 +2,38 @@
5
6
7 def attach_celery_info(report, context):
8+ """Attach celery info from the context to the oops report.
9+
10+ TaskOopsReporter puts info about the celery failure in the
11+ oops context. This hook moves that information to the
12+ report, which is what is usually desired. If you want to do
13+ something different then use a different hook.
14+ """
15 for key, value in context.items():
16 if key.startswith('celery.'):
17 report[key] = value
18
19
20 class TaskOopsReporter(object):
21+ """Create an oops report when on_failure is called.
22+
23+ This object has a callback designed to be used with celery's signals
24+ to create oops reports when celery task failures are triggered.
25+ """
26
27 def __init__(self, config):
28+ """Create an oops reporter.
29+
30+ :param config: the oops.Config object to create the oops from
31+ and publish it to.
32+ """
33 self.config = config
34
35 def on_failure(self, einfo=None, **kwargs):
36+ """Callback to create an oops.
37+
38+ Designed to be used with `celery.signals.on_failure`.
39+ """
40 context = dict()
41 if einfo is not None:
42 context['exc_info'] = einfo.exc_info
43@@ -23,6 +44,20 @@
44
45
46 def setup_oops_reporter(config):
47+ """Setup an oops reporter to be triggered when a celery job fails.
48+
49+ This creates a `TaskOopsReporter` object using the passed config,
50+ and sets up `attach_celery_info` to be called when an oops is
51+ created. Finally it connects `TaskOopsReporter.on_failure` to
52+ `celery.signal.task_failure` so that it is called when tasks
53+ fail.
54+
55+ If you wish to have a different setup then you can implement those
56+ steps yourself.
57+
58+ :param config: the oops.Config to use fore creating and publishing
59+ the oops.
60+ """
61 config.on_create.append(attach_celery_info)
62 reporter = TaskOopsReporter(config)
63 signals.task_failure.connect(reporter.on_failure, weak=False)

Subscribers

People subscribed via source and target branches