[Answer]-Monitor Management Command Execution in Django

1👍

Wrap your read function in a try/except block marking some external memoization for execution control. I’m using Redis as an example:

from redis import Redis

try:
    r_client = Redis() # assuming standard settings
    sentinel = r_client.incr("my_sentinel")
    if sentinel == 1:
        run_command()
    else:
        r_client.decr("my_sentinel")
except Exception as e:
    r_client.decr("my_sentinel")
    raise e

0👍

You could create a file named “i_am_running.log” at the beginning of your management command and remove it at the end if it. When running same management command, check for its’ presence. In case of no exist – go further. Otherwise – abort.

Leave a comment