Skip to content
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

Adding human readable descriptions of crontab schedules #622

Merged
merged 5 commits into from
Mar 2, 2023

Conversation

truthdoug
Copy link
Contributor

Partially addresses #612

What I did

  • incorporated cron-descriptor to provide more readable descriptions of crontab schedules
  • added these descriptions on the PeriodicTask detail view on and the Crontab list view
  • updated help text for Crontab to help me remember how the numbers translate to days of the week
  • modest updates to locales

What is missing

  • testing of non-English locales
  • translation of new help text for locales other than English, Spanish, and German

Possible problems

  • The human readable text of all crontabs is loaded into the context of the PeriodicTask detail view. This could be a problem for sites that have a very large number of crontab schedules.

@auvipy auvipy self-requested a review December 23, 2022 07:14
@truthdoug truthdoug force-pushed the issue612 branch 2 times, most recently from 2d096c6 to 8fef408 Compare December 23, 2022 23:04
def changeform_view(self, request, object_id=None, form_url='',
extra_context=None):
extra_context = extra_context or {}
crontabs = CrontabSchedule.objects.all()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

instead of calling all, can we reduce the number?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, I'm not sure how we'd decide which to include. My goal here is to provide natural language translations for all available crontabs.

The best argument for reducing the number is possible slow response times when loading the page. But, based on other sites I've used that load a lot of data into javascript objects onto the DOM, my hunch is that there would have to be hundreds (if not thousands) of CrontabSchedule objects before it would impact performance of this page. Additionally, since this is an admin-only view, any hit to responsiveness would never be seen by end users.

Do you have thoughts on how we might choose which ones to reduce it to?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we show 20/25 per page?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear to me how paginating this would work.

My goal with this change is to update the human readable description anytime the user changes the select list of defined crontabs. So, if I change from 5 * * * * to 0 10 * * 1, I want the description to change from "At 5 minutes past the hour" to "At 10:00 AM, only on Monday" to verify that the change is what I expect.

If the code only loads 20 per page, what happens if I choose a crontab that wasn't part of the 20 that were loaded?

This could be implemented as ajax/XHR so that the description is readable only on demand. Since django-celery-beat doesn't currently have any custom endpoints defined, this seems like a bigger change. Alternately, there could be a setting to disable this if a site has so many CrontabSchedules defined that loading this admin page is onerous.

Can you tell me more about your objection to having all defined on this page?

`${originalCrontabHelp}<br/>Translation: ${additional}`);
};

django.jQuery(".field-crontab_translation").hide()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this django.jQuery being used from django admin itself? is it possible to switch to plain vanilla JS here? ES 6 without any dependencies?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From django documentation:

To avoid conflicts with user-supplied scripts or libraries, Django’s jQuery (version 3.6.0) is namespaced as django.jQuery.

Since this namespaced jQuery comes with Django admin, this seems like the best choice for using jQuery. It's probably possible to use ES 6 w/o dependencies but jQuery is not an extra dependency, so I think using this is ok.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok make sense

def changeform_view(self, request, object_id=None, form_url='',
extra_context=None):
extra_context = extra_context or {}
crontabs = CrontabSchedule.objects.all()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we show 20/25 per page?

@auvipy
Copy link
Member

auvipy commented Feb 7, 2023

I am not sure why CI is failing. can you check please?

@@ -616,7 +626,7 @@ def schedule(self):
if self.interval:
return self.interval.schedule
if self.crontab:
return self.crontab.schedule
return self.crontab
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some unit tests are failed because of this change.
Can you elaborate more on why we need this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recently closed PR #621 because I realized the changes are already covered in yours.
Hope this can give you an idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can merge part of your PR first @khanh96le

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @auvipy. I saw that you already reopened it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the change you made in #621, @khanh96le! That's an improved list view!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure @auvipy. I saw that you already reopened it

can you give this PR another round of review?

@auvipy
Copy link
Member

auvipy commented Feb 7, 2023

builds are now passing after merging your PR @khanh96le

@auvipy auvipy merged commit 8f9fd1b into celery:main Mar 2, 2023
@auvipy
Copy link
Member

auvipy commented Mar 2, 2023

The human readable text of all crontabs is loaded into the context of the PeriodicTask detail view. This could be a problem for sites that have a very large number of crontab schedules. --- we need to find a solution for this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants