3636from alws .utils .multilib import MultilibProcessor
3737from alws .utils .noarch import save_noarch_packages
3838from alws .utils .parsing import clean_release , parse_rpm_nevra
39- from alws .utils .pulp_client import PulpClient
39+ from alws .utils .pulp_client import PulpClient , get_pulp_client
4040from alws .utils .pulp_utils import get_module_from_pulp_db
4141from alws .utils .rpm_package import get_rpm_packages_info
4242
@@ -47,9 +47,22 @@ async def get_available_build_task(
4747) -> typing .Optional [models .BuildTask ]:
4848 # TODO: here should be config value
4949 ts_expired = datetime .datetime .utcnow () - datetime .timedelta (minutes = 20 )
50+ exclude_condition = (
51+ sqlalchemy .not_ (
52+ sqlalchemy .or_ (* [
53+ models .BuildTaskRef .url .ilike (f"%{ project } %" )
54+ for project in request .excluded_packages
55+ ])
56+ )
57+ if request .excluded_packages
58+ else True
59+ )
5060 db_task = await db .execute (
5161 select (models .BuildTask )
5262 .where (~ models .BuildTask .dependencies .any ())
63+ .join (
64+ models .BuildTask .ref ,
65+ )
5366 .with_for_update ()
5467 .filter (
5568 sqlalchemy .and_ (
@@ -59,6 +72,7 @@ async def get_available_build_task(
5972 models .BuildTask .ts < ts_expired ,
6073 models .BuildTask .ts .is_ (None ),
6174 ),
75+ exclude_condition ,
6276 )
6377 )
6478 .options (
@@ -236,16 +250,16 @@ async def log_repo_exists(db: AsyncSession, task: models.BuildTask):
236250
237251
238252async def create_build_log_repo (db : AsyncSession , task : models .BuildTask ):
239- pulp_client = PulpClient (
240- settings .pulp_host , settings .pulp_user , settings .pulp_password
241- )
253+ pulp_client = get_pulp_client ()
242254 repo_name = task .get_log_repo_name ()
243255 pulp_repo = await pulp_client .get_log_repository (repo_name )
244256 if pulp_repo :
245257 pulp_href = pulp_repo ["pulp_href" ]
246258 distro = await pulp_client .get_log_distro (repo_name )
247259 if not distro :
248- repo_url = await pulp_client .create_file_distro (repo_name , pulp_href )
260+ repo_url = await pulp_client .create_file_distro (
261+ repo_name , pulp_href
262+ )
249263 else :
250264 repo_url = distro ["base_url" ]
251265 else :
@@ -372,7 +386,9 @@ def get_repo(repo_arch, is_debug):
372386 try :
373387 results = await asyncio .gather (* tasks )
374388 except Exception as e :
375- logging .exception ("Cannot create RPM packages for repo %s" , str (repo ))
389+ logging .exception (
390+ "Cannot create RPM packages for repo %s" , str (repo )
391+ )
376392 raise ArtifactConversionError (
377393 f"Cannot put RPM packages into Pulp storage: { e } "
378394 )
@@ -449,7 +465,9 @@ def append_errata_package(_, errata_package, artifact, rpm_info):
449465 if rpm_info ["arch" ] != "noarch" :
450466 conditions .append (models .NewErrataPackage .arch == rpm_info ["arch" ])
451467
452- query = select (models .NewErrataPackage ).where (sqlalchemy .and_ (* conditions ))
468+ query = select (models .NewErrataPackage ).where (
469+ sqlalchemy .and_ (* conditions )
470+ )
453471
454472 if module_index :
455473 module = None
@@ -502,7 +520,9 @@ def append_errata_package(_, errata_package, artifact, rpm_info):
502520 try :
503521 for module in module_index .iter_modules ():
504522 for artifact in module_artifacts :
505- module .add_rpm_artifact (artifact , task_excluded = task_excluded )
523+ module .add_rpm_artifact (
524+ artifact , task_excluded = task_excluded
525+ )
506526 except Exception as e :
507527 raise ModuleUpdateError ("Cannot update module: %s" , str (e )) from e
508528
@@ -645,14 +665,18 @@ def _get_srpm_name(
645665 if build_repo .arch == build_task .arch and build_repo .debug is False
646666 )
647667 try :
648- repo_modules_yaml = await pulp_client .get_repo_modules_yaml (module_repo .url )
668+ repo_modules_yaml = await pulp_client .get_repo_modules_yaml (
669+ module_repo .url
670+ )
649671 module_index = IndexWrapper .from_template (repo_modules_yaml )
650672 except Exception as e :
651673 message = f"Cannot parse modules index: { str (e )} "
652674 logging .exception ("Cannot parse modules index: %s" , str (e ))
653675 raise ModuleUpdateError (message ) from e
654676 rpm_artifacts = [item for item in task_artifacts if item .type == "rpm" ]
655- log_artifacts = [item for item in task_artifacts if item .type == "build_log" ]
677+ log_artifacts = [
678+ item for item in task_artifacts if item .type == "build_log"
679+ ]
656680 src_rpm = _get_srpm_name (
657681 artifacts = task_artifacts ,
658682 task = build_task ,
@@ -822,7 +846,9 @@ def _get_srpm_name(
822846 module_for_pulp .description ,
823847 version = module_version ,
824848 artifacts = module_for_pulp .get_rpm_artifacts (),
825- dependencies = list (module_for_pulp .get_runtime_deps ().values ()),
849+ dependencies = list (
850+ module_for_pulp .get_runtime_deps ().values ()
851+ ),
826852 # packages=module_pkgs_hrefs,
827853 packages = [],
828854 profiles = module_for_pulp .get_profiles (),
@@ -840,7 +866,9 @@ def _get_srpm_name(
840866 "delta" : str (end_time - start_time ),
841867 }
842868 except Exception as e :
843- message = f"Cannot update module information inside Pulp: { str (e )} "
869+ message = (
870+ f"Cannot update module information inside Pulp: { str (e )} "
871+ )
844872 logging .exception (message )
845873 raise ModuleUpdateError (message ) from e
846874 logging .info ("Module template processing is finished" )
@@ -998,7 +1026,7 @@ async def safe_build_done(
9981026 request : build_node_schema .BuildDone ,
9991027):
10001028 success = True
1001- pulp = PulpClient ( settings . pulp_host , settings . pulp_user , settings . pulp_password )
1029+ pulp = get_pulp_client ( )
10021030 build_task_stats = {
10031031 "build_node_stats" : request .stats ,
10041032 "build_done_stats" : {},
@@ -1013,7 +1041,9 @@ async def safe_build_done(
10131041 logging .exception ("Build done failed:" )
10141042 success = False
10151043 build_task = await db .execute (
1016- select (models .BuildTask ).where (models .BuildTask .id == request .task_id )
1044+ select (models .BuildTask ).where (
1045+ models .BuildTask .id == request .task_id
1046+ )
10171047 )
10181048 build_task = build_task .scalars ().first ()
10191049 build_task .ts = datetime .datetime .utcnow ()
@@ -1034,9 +1064,12 @@ async def safe_build_done(
10341064 await db .flush ()
10351065 finally :
10361066 remove_dep_query = delete (models .BuildTaskDependency ).where (
1037- models .BuildTaskDependency .c .build_task_dependency == request .task_id
1067+ models .BuildTaskDependency .c .build_task_dependency
1068+ == request .task_id
1069+ )
1070+ build_task_start_time = request .stats .get ("build_node_task" , {}).get (
1071+ "start_ts"
10381072 )
1039- build_task_start_time = request .stats .get ("build_node_task" , {}).get ("start_ts" )
10401073 if build_task_start_time :
10411074 build_task_start_time = datetime .datetime .fromisoformat (
10421075 build_task_start_time
0 commit comments