-
Notifications
You must be signed in to change notification settings - Fork 86
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 6 commits
30261b0
8831f1d
d402b4d
0e7a745
01fb783
69c482b
e56726c
2a01a5b
4ec1563
d6e26f5
4fd2266
5cb2550
588c027
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 | ||
|---|---|---|---|---|
|
|
@@ -12,24 +12,14 @@ | |||
| @admin.register(Task) | ||||
| class TaskAdmin(admin.ModelAdmin): | ||||
| exclude = ("message_data",) | ||||
| readonly_fields = ("message_details", "traceback", "status", "queue_name", "actor_name") | ||||
| list_display = ( | ||||
| "__str__", | ||||
| "status", | ||||
| "eta", | ||||
| "created_at", | ||||
| "updated_at", | ||||
| "queue_name", | ||||
| "actor_name", | ||||
| ) | ||||
| readonly_fields = ("message_details", "traceback", "status", "queue_name", "actor_name", "created_at", "updated_at") | ||||
| list_display = ("__str__", "status", "eta", "created_at", "updated_at", "queue_name", "actor_name") | ||||
| list_filter = ("status", "created_at", "queue_name", "actor_name") | ||||
| search_fields = ("actor_name",) | ||||
|
|
||||
| def eta(self, instance): | ||||
| timestamp = ( | ||||
| instance.message.options.get("eta", instance.message.message_timestamp) / 1000 | ||||
| ) | ||||
|
|
||||
| """Estimated time of arrival""" | ||||
|
Collaborator
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. What would be the value of this docstring? It just deciphers a common-known abbreviation, which the function named after.
Author
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. 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
Collaborator
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.
Suggested change
I would agree with @amureki on this. Lets remove it before merging.
Author
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. Are you serious? How can the documentation line interfere?
Author
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. 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.
Author
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. One more argument: By the way, is "Estimated time of arrival" the correct decoding of ETA? |
||||
| timestamp = (instance.message.options.get("eta", instance.message.message_timestamp) / 1000) | ||||
| # Django expects a timezone-aware datetime if USE_TZ is True, and a naive datetime in localtime otherwise. | ||||
| tz = timezone.utc if settings.USE_TZ else None | ||||
| return datetime.fromtimestamp(timestamp, tz=tz) | ||||
|
|
||||
| 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__) | ||
|
Collaborator
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.
Author
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__) | ||
|
Collaborator
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. 😉
Author
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}' | ||
|
Collaborator
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?
Author
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", | ||
|
Collaborator
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 to change the name of the project?? 🤔
Author
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. Yes, Here is rules: This is not killer fature, but useful. If I saw such a MR for my library, I would also double-check everything 100 times.
Collaborator
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.
I dont think this is the case, and its most likely due to the number of public repo dependents being less than 100..
Author
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. Maybe so, I suggest you try, and if anything, you can roll back the changes in the minor release immediately after the release. |
||
| version=version, | ||
| description="A Django app for Dramatiq.", | ||
| long_description="Visit https://github.com/Bogdanp/django_dramatiq for more information.", | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.