-
Notifications
You must be signed in to change notification settings - Fork 79
TaskAdmin+fields(created_at,updated_at), ideomatic logger, TaskManager TaskManager __str__ try #118
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 7 commits
30261b0
8831f1d
d402b4d
0e7a745
01fb783
69c482b
e56726c
2a01a5b
4ec1563
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
from django import db | ||
from dramatiq.middleware import Middleware | ||
|
||
LOGGER = logging.getLogger("django_dramatiq.AdminMiddleware") | ||
logger = logging.getLogger(__name__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: Any reason for this change? ie. this is potentially a breaking change for people relying on the namespacing of this logger. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logger naming for this place is not ideomatic, there is no reasons to do this like here. Anyway the log path will be the same here. A potential problem may look like this: they changed the name of the class and forgot to change it in the logger. This approach would be logical if you specified a single name for the entire package, for example: "django_dramatiq_all_pain" however, it is obvious from this place that there was no such goal. |
||
|
||
|
||
class AdminMiddleware(Middleware): | ||
|
@@ -13,7 +13,7 @@ class AdminMiddleware(Middleware): | |
def after_enqueue(self, broker, message, delay): | ||
from .models import Task | ||
|
||
LOGGER.debug("Creating Task from message %r.", message.message_id) | ||
logger.debug("Creating Task from message %r.", message.message_id) | ||
status = Task.STATUS_ENQUEUED | ||
if delay: | ||
status = Task.STATUS_DELAYED | ||
|
@@ -28,7 +28,7 @@ def after_enqueue(self, broker, message, delay): | |
def before_process_message(self, broker, message): | ||
from .models import Task | ||
|
||
LOGGER.debug("Updating Task from message %r.", message.message_id) | ||
logger.debug("Updating Task from message %r.", message.message_id) | ||
Task.tasks.create_or_update_from_message( | ||
message, | ||
status=Task.STATUS_RUNNING, | ||
|
@@ -49,7 +49,7 @@ def after_process_message(self, broker, message, *, result=None, exception=None, | |
elif status is None: | ||
status = Task.STATUS_DONE | ||
|
||
LOGGER.debug("Updating Task from message %r.", message.message_id) | ||
logger.debug("Updating Task from message %r.", message.message_id) | ||
Task.tasks.create_or_update_from_message( | ||
message, | ||
status=status, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
import logging | ||
from datetime import timedelta | ||
|
||
from django.db import models | ||
|
@@ -10,6 +11,8 @@ | |
#: The database label to use when storing task metadata. | ||
DATABASE_LABEL = DjangoDramatiqConfig.tasks_database() | ||
|
||
logger = logging.getLogger(__name__) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue: Same issue as above. 😉 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. *above |
||
|
||
|
||
class TaskManager(models.Manager): | ||
def create_or_update_from_message(self, message, **extra_fields): | ||
|
@@ -63,4 +66,8 @@ def message(self): | |
return Message.decode(bytes(self.message_data)) | ||
|
||
def __str__(self): | ||
return str(self.message) | ||
try: | ||
return str(self.message) | ||
except Exception as e: | ||
logger.exception(f'Failed to display Task {self.id}') | ||
return f'Failed to display Task: {e}' | ||
Comment on lines
+69
to
+73
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Under what condition would this raise? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As I told above The key feature here is that the database cannot guarantee us the encodability of a BinaryField data. And I finally found the trace!
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ def rel(*xs): | |
|
||
|
||
setup( | ||
name="django_dramatiq", | ||
name="django-dramatiq", | ||
|
||
version=version, | ||
description="A Django app for Dramatiq.", | ||
long_description="Visit https://github.com/Bogdanp/django_dramatiq for more information.", | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What would be the value of this docstring? It just deciphers a common-known abbreviation, which the function named after.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First time I took a few moments to decipher it, as I didn't meet her very often. I think it definitely won't hurt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would agree with @amureki on this. Lets remove it before merging.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you serious? How can the documentation line interfere?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I conducted a survey among 10 of my colleagues: "I know exactly what the abbreviation ETA stands for." Most of them are engineers. The result: 40% know for sure.
I didn't think I'd have to defend the docstring either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more argument:
Explicit is better than implicit.
:D
By the way, is "Estimated time of arrival" the correct decoding of ETA?