1616
1717from celery import shared_task
1818
19+ from django .core .cache import cache
20+
1921from errata .sources .distros .arch import update_arch_errata
2022from errata .sources .distros .alma import update_alma_errata
2123from errata .sources .distros .debian import update_debian_errata
2224from errata .sources .distros .centos import update_centos_errata
2325from errata .sources .distros .rocky import update_rocky_errata
2426from errata .sources .distros .ubuntu import update_ubuntu_errata
25- from util .logging import error_message
27+ from util .logging import error_message , warning_message
2628from repos .models import Repository
2729from security .tasks import update_cves , update_cwes
2830from util import get_setting_of_type
@@ -44,34 +46,44 @@ def update_yum_repo_errata(repo_id=None, force=False):
4446def update_errata (erratum_type = None , force = False , repo = None ):
4547 """ Update all distros errata
4648 """
47- errata_os_updates = []
48- erratum_types = ['yum' , 'rocky' , 'alma' , 'arch' , 'ubuntu' , 'debian' , 'centos' ]
49- erratum_type_defaults = ['yum' , 'rocky' , 'alma' , 'arch' , 'ubuntu' , 'debian' ]
50- if erratum_type :
51- if erratum_type not in erratum_types :
52- error_message .send (sender = None , text = f'Erratum type `{ erratum_type } ` not in { erratum_types } ' )
53- else :
54- errata_os_updates = erratum_type
49+ lock_key = 'update_errata_lock'
50+ # lock will expire after 48 hours
51+ lock_expire = 60 * 60 * 48
52+
53+ if cache .add (lock_key , 'true' , lock_expire ):
54+ try :
55+ errata_os_updates = []
56+ erratum_types = ['yum' , 'rocky' , 'alma' , 'arch' , 'ubuntu' , 'debian' , 'centos' ]
57+ erratum_type_defaults = ['yum' , 'rocky' , 'alma' , 'arch' , 'ubuntu' , 'debian' ]
58+ if erratum_type :
59+ if erratum_type not in erratum_types :
60+ error_message (text = f'Erratum type `{ erratum_type } ` not in { erratum_types } ' )
61+ else :
62+ errata_os_updates = erratum_type
63+ else :
64+ errata_os_updates = get_setting_of_type (
65+ setting_name = 'ERRATA_OS_UPDATES' ,
66+ setting_type = list ,
67+ default = erratum_type_defaults ,
68+ )
69+ if 'yum' in errata_os_updates :
70+ update_yum_repo_errata (repo_id = repo , force = force )
71+ if 'arch' in errata_os_updates :
72+ update_arch_errata ()
73+ if 'alma' in errata_os_updates :
74+ update_alma_errata ()
75+ if 'rocky' in errata_os_updates :
76+ update_rocky_errata ()
77+ if 'debian' in errata_os_updates :
78+ update_debian_errata ()
79+ if 'ubuntu' in errata_os_updates :
80+ update_ubuntu_errata ()
81+ if 'centos' in errata_os_updates :
82+ update_centos_errata ()
83+ finally :
84+ cache .delete (lock_key )
5585 else :
56- errata_os_updates = get_setting_of_type (
57- setting_name = 'ERRATA_OS_UPDATES' ,
58- setting_type = list ,
59- default = erratum_type_defaults ,
60- )
61- if 'yum' in errata_os_updates :
62- update_yum_repo_errata (repo_id = repo , force = force )
63- if 'arch' in errata_os_updates :
64- update_arch_errata ()
65- if 'alma' in errata_os_updates :
66- update_alma_errata ()
67- if 'rocky' in errata_os_updates :
68- update_rocky_errata ()
69- if 'debian' in errata_os_updates :
70- update_debian_errata ()
71- if 'ubuntu' in errata_os_updates :
72- update_ubuntu_errata ()
73- if 'centos' in errata_os_updates :
74- update_centos_errata ()
86+ warning_message ('Already updating Errata, skipping task.' )
7587
7688
7789@shared_task
0 commit comments