celery time limit

hyuckhoon.ko·2022년 8월 18일
0

1. time limit

A single task can potentially run forever, if you have lots of tasks waiting for some event that’ll never happen you’ll block the worker from processing new tasks indefinitely. The best way to defend against this scenario happening is enabling time limits.

The time limit (–time-limit) is the maximum number of seconds a task may run before the process executing it is terminated and replaced by a new process. You can also enable a soft time limit (–soft-time-limit), this raises an exception the task can catch to clean up before the hard time limit kills it:

2. soft vs hard

The time limit is set in two values, soft and hard. The soft time limit allows the task to catch an exception to clean up before it is killed: the hard timeout isn’t catch-able and force terminates the task.

3. 필요성

@shared_task(base=Singleton, soft_time_limit=850)
def cancel_lack_player_match():
    try:
        from time import sleep
        sleep(900)
		
        
    except SoftTimeLimitExceeded:
        pass

0개의 댓글