Skip to content

Instantly share code, notes, and snippets.

View juanwolf's full-sized avatar
🍅

Jean-Loup Adde juanwolf

🍅
View GitHub Profile
crontab = settings.CELERYBEAT_SCHEDULE['mytask']['schedule']
# We get the duration until the next execution
delta = crontab.remaining_estimate(crontab.now())
# We get the datetime of the next execution
next_exec = datetime.now() + delta
# We get the duration between two execution
duration = crontab.remaining_estimate(next_exec) - delta
# So the last run is the next_exec minus the duration between two task.
last_run = next_exec - duration
@juanwolf
juanwolf / debug_middleware.py
Last active November 28, 2019 09:28
DRF Debug JSON Format
# Code adapted for django 1.10 and python3 from https://stackoverflow.com/a/19249559/2622605
from django.http import HttpResponse
import json
class NonHtmlDebugToolbarMiddleware:
"""
The Django Debug Toolbar usually only works for views that return HTML.
This middleware wraps any non-HTML response in HTML if the request

Keybase proof

I hereby claim:

  • I am juanwolf on github.
  • I am juanwolf (https://keybase.io/juanwolf) on keybase.
  • I have a public key ASCnr_rBGYD278iJnxFTkYYhzLHJaQeLxDgxFR7KUBYWgwo

To claim this, I am signing this object: