Created
April 5, 2020 13:59
-
-
Save Enforcer/c3a884c77b424977cb0d69893a60134b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.task(soft_time_limit=5, time_limit=10) | |
def time_limited_task(): | |
""" | |
This task has time limits to ensure it will never work for | |
longer than anticipated. | |
soft_time_limit is a number of seconds when SoftTimeLimitExceeded | |
is raised to give a moment to clean up. | |
time_limit is a number of seconds after task is terminated unconditionally | |
""" | |
will_sleep_for = randint(5, 15) | |
logger.info(f'Work started (need {will_sleep_for}s to finish)') | |
try: | |
sleep(will_sleep_for) | |
except SoftTimeLimitExceeded: | |
logger.info('Oups, soft limit exceeded! Quickly, clean up!') | |
sleep(will_sleep_for) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment