procrastinate icon indicating copy to clipboard operation
procrastinate copied to clipboard

Add Django admin action to reschedule "todo" job

Open mschfh opened this issue 6 months ago • 11 comments

Please implement a Django admin action to reschedule a job that was deferred with schedule_in (or is waiting for a retry backoff) to the current time instead of waiting for the configured delay.

mschfh avatar Jul 06 '25 12:07 mschfh

Hello! Is there something specific that means this needs to live in Procrastinate rather than in your code ?

ewjoachim avatar Jul 07 '25 08:07 ewjoachim

Procrastinate includes the Django admin in django.contrib.admin

mschfh avatar Jul 08 '25 20:07 mschfh

I believe you can unregister it and register your own subclass that has custom behaviour?

Not saying it's a bad idea or anything, but given how bare-bones the Django Admin is, I'm not sure it would make sense to include very specific features like this before other more common usecases. Also, we tried in our design to make procrastinate "hackable" (in the sense: that we try to make it so that people can do things with it that we didn't intended, and it still works), and I'm genuinely interested to better understand if customizing the Django admin ends up being an easy task or not.

ewjoachim avatar Jul 08 '25 22:07 ewjoachim

I'm genuinely interested to better understand if customizing the Django admin ends up being an easy task or not

To a certain degree, yes, adding this action likely just requires a simple function with a @admin.action() decorator, I'll look into it and create a PR if this is the case.

mschfh avatar Jul 09 '25 05:07 mschfh

Thanks for the PR. My initial question was: starting from the code of your PR, do you need this to be merged in Procrastinate in order to benefit from it ?

If you do the following in your own code:

@admin.action(
    description="Reschedule marked jobs to run now", permissions=["reschedule"]
)
def reschedule(modeladmin, request, queryset):
    ...

admin.unregister(models.ProcrastinateJob)

@admin.register(models.ProcrastinateJob)
class CustomProcrastinateJobAdmin(ProcrastinateJobAdmin):
    actions = ProcrastinateJobAdmin.actions + [reschedule]
    

Then does it work as intended for your usecase ?

ewjoachim avatar Jul 09 '25 12:07 ewjoachim

Thanks, It works as intended for my use case, so this does not need to be merged into Procrastinate, but IMHO it would still be a convenient feature.

but given how bare-bones the Django Admin is, I'm not sure it would make sense to include very specific features like this before other more common usecases

Are there existing issues or specific ideas for other improvements? It should be reasonably simple to add additional actions (cancel, retry, etc), let me know if there is interest in another PR.

mschfh avatar Jul 14 '25 06:07 mschfh

I think I don't envision the Django Admin interface to become really advanced (in particular, more advanced than the other interface) because it's not made for that, and it's going to play badly for anyone with customizations (Django Grapelli etc). Adding precise UI in Django admin feels like you're fighting against the machine. This is an autogenerated admin meant to follow the way your data is stored in the DB.

In contrast, I'd love the idea of a proper web interface (like celery flower for celery), independant of Django, and using modern web practices (so that would autoupdate, without constant polls, so websocket? SSE?). There's an issue for that, but I'm on mobile and it's hard to search.

Might be an opportunity to try out htmx and maybe fasthtml or htpy. This could live in a different repo under the Procrastinate umbrella.

Well, you have it, that's my current stance :) It could evolved if presented with convincing arguments.

ewjoachim avatar Jul 14 '25 07:07 ewjoachim

I think I don't envision the Django Admin interface to become really advanced

Me neither, I would have suggested to implement similar functionality as the existing CLI (and ideally implement the reschedule command for the CLI to have parity).

it's going to play badly for anyone with customizations (Django Grapelli etc). Adding precise UI in Django admin feels like you're fighting against the machine. This is an autogenerated admin meant to follow the way your data is stored in the DB.

The Django admin is extensible by design and supports admin actions natively (without any template changes, etc) - if a third party package breaks this core functionality, it will affect other parts of Django as well.

Having a separate web interface would be nice, but also add complexity (deployment/monitoring/auth/etc), the Django admin is already included and provides basic job management.

--

Considering the above, would you be open to:

  • a PR to implement minimal retry/cancel Django actions (similar to the shell commands)?
  • an updated PR to also implement thereschedule action as a shell command?

mschfh avatar Jul 15 '25 09:07 mschfh

Considering the above, would you be open to:

  • a PR to implement minimal retry/cancel Django actions (similar to the shell commands)?

retry/cancel definitly makes sense as a Django admin action.

  • an updated PR to also implement the reschedule action as a shell command?

I'm not sure I understand if this action will be useful for a lot of folks, or covers a very specific usecase. Can you tell me more on why this is important to you and how it will help other users ?

ewjoachim avatar Jul 15 '25 09:07 ewjoachim

a PR to implement minimal retry/cancel Django actions (similar to the shell commands)?

Actually, unrelatedlym #1325 (about to be merged) actually does it already :)

ewjoachim avatar Jul 16 '25 23:07 ewjoachim

  • an updated PR to also implement the reschedule action as a shell command?

I'm not sure I understand if this action will be useful for a lot of folks, or covers a very specific usecase. Can you tell me more on why this is important to you and how it will help other users ?

The main use case is to "immediately" run jobs stuck in an exponential backoff or scheduled in the future via schedule_in(). Currently, those can only be rescheduled by manually updating scheduled_at in the database.

mschfh avatar Jul 21 '25 18:07 mschfh