Skip to content

Commit 4b1f62c

Browse files
committed
flakes
1 parent adb2b13 commit 4b1f62c

File tree

6 files changed

+24
-25
lines changed

6 files changed

+24
-25
lines changed

Changelog

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818

1919
Fix contributed by Brett Gibson.
2020

21-
- celerycam: The cleanup phase now commits the transaction for every row
22-
deleted.
21+
- No longer uses manual transaction management to be compatible with Django
22+
1.6.
2323

24-
This is likely to make the cleanup considerably slower, but needs to work
25-
with Django 1.6.
24+
This will probably decrease performance considerably, e.g. for clean up
25+
of celerycam events and for celerybeat which now needs to commit the
26+
transaction for every operation.
2627

2728
- The `celery` management command now performs validation checks (Issue #253).
2829

djcelery/db.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
from django.db import transaction
55

66
try:
7-
from django.db.transaction import atomic
7+
from django.db.transaction import atomic # noqa
88
except ImportError: # pragma: no cover
99

1010
try:
11-
from django.db.transaction import Transaction
11+
from django.db.transaction import Transaction # noqa
1212
except ImportError:
1313
@contextmanager
1414
def commit_on_success(*args, **kwargs):
@@ -31,7 +31,7 @@ def commit_on_success(*args, **kwargs):
3131
finally:
3232
transaction.leave_transaction_management(*args, **kwargs)
3333
else: # pragma: no cover
34-
from django.db.transaction import commit_on_success # noqa
34+
from django.db.transaction import commit_on_success # noqa
3535

3636
commit_unless_managed = transaction.commit_unless_managed
3737
rollback_unless_managed = transaction.rollback_unless_managed
@@ -51,4 +51,3 @@ def commit_unless_managed(*args, **kwargs): # noqa
5151

5252
def rollback_unless_managed(*args, **kwargs): # noqa
5353
pass
54-

djcelery/managers.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from functools import wraps
66
from itertools import count
77

8-
from django.db import transaction, connection
8+
from django.db import connection
99
try:
1010
from django.db import connections, router
1111
except ImportError: # pre-Django 1.2
@@ -17,9 +17,7 @@
1717

1818
from celery.utils.timeutils import maybe_timedelta
1919

20-
from .db import (
21-
commit_on_success, commit_unless_managed, rollback_unless_managed,
22-
)
20+
from .db import commit_on_success, rollback_unless_managed
2321
from .utils import now
2422

2523

@@ -237,13 +235,10 @@ def expire_by_states(self, states, expires):
237235
return self.expired(states, expires).update(hidden=True)
238236

239237
def purge(self):
240-
meta = self.model._meta
241-
cursor = self.connection_for_write().cursor()
242-
cursor.execute(
243-
'DELETE FROM {0.db_table} WHERE hidden=%s'.format(meta),
244-
(True, ),
245-
)
246-
try:
247-
commit_unless_managed()
248-
except transaction.TransactionManagementError:
249-
pass
238+
with commit_on_success():
239+
meta = self.model._meta
240+
cursor = self.connection_for_write().cursor()
241+
cursor.execute(
242+
'DELETE FROM {0.db_table} WHERE hidden=%s'.format(meta),
243+
(True, ),
244+
)

djcelery/snapshot.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from celery.utils.log import get_logger
1313
from celery.utils.timeutils import maybe_iso8601
1414

15-
from .db import commit_on_success
1615
from .models import WorkerState, TaskState
1716
from .utils import maybe_make_aware
1817

djcelery/tests/test_snapshot.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
_next_id = count(0).next
1818
_next_clock = count(1).next
1919

20+
2021
def Event(*args, **kwargs):
2122
kwargs.setdefault('clock', _next_clock())
2223
kwargs.setdefault('local_received', time())

djcelery/views.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,12 @@ def add(request):
100100
y = int(request.GET['y'])
101101
return x + y
102102
103-
>>> response = add(request)
104-
>>> response.content
103+
def view(request):
104+
response = add(request)
105+
print(response.content)
106+
107+
Gives::
108+
105109
"{'status': 'success', 'retval': 100}"
106110
107111
"""

0 commit comments

Comments
 (0)