mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 04:53:36 +00:00
purge-old-deployments: Avoid purging last/next deployments.
This commit is contained in:
@@ -11,15 +11,20 @@ from zulip_tools import DEPLOYMENTS_DIR, TIMESTAMP_FORMAT
|
||||
logging.basicConfig(format="%(asctime)s purge-deployments: %(message)s",
|
||||
level=logging.INFO)
|
||||
|
||||
deployments_in_use = set()
|
||||
for basename in ['current', 'last', 'next']:
|
||||
# Note which symlinks are current
|
||||
path = os.path.abspath(os.readlink(os.path.join(DEPLOYMENTS_DIR, basename)))
|
||||
deployments_in_use.add(path)
|
||||
|
||||
one_week_ago = datetime.datetime.now() - datetime.timedelta(days=7)
|
||||
to_purge = []
|
||||
for filename in os.listdir(DEPLOYMENTS_DIR):
|
||||
try:
|
||||
date = datetime.datetime.strptime(filename, TIMESTAMP_FORMAT)
|
||||
if date < one_week_ago:
|
||||
if (os.path.abspath(os.readlink("/home/zulip/deployments/current")) ==
|
||||
os.path.abspath(os.path.join(DEPLOYMENTS_DIR, filename))):
|
||||
# Never purge the currently running deployment
|
||||
if os.path.abspath(os.path.join(DEPLOYMENTS_DIR, filename)) in deployments_in_use:
|
||||
# Never purge an in-use deployment
|
||||
continue
|
||||
to_purge.append(filename)
|
||||
except ValueError:
|
||||
|
||||
Reference in New Issue
Block a user