'i(lSrSSKrSSKJrJrJrJr SSKJr SSKJ r SSK J r SSK J r "SS 5rg) zs Dependency Manager for Python Scheduler Handles job chaining and execution order with configurable error handling N)ListDictAnyOptional)datetime)logger)SchedulerDatabase) JobExecutorc \rSrSrSrS\S\4SjrSS\S\ S\ \ \ 44S jjr SS \S \ S \ S\ 4S jjrSS\ S\\S\ S\ S\4 SjjrSS\S\S\\ \ \ 44SjjrS\S\ \ \ 44SjrSrg)DependencyManagerz-Manages job dependencies and execution chainsdbexecutorcHXlX l[R"S5 g)NzDependencyManager initialized)rrrinfo)selfrrs 0c:\PYTHON\Scheduler\daemon\dependency_manager.py__init__DependencyManager.__init__s  34group_id triggered_byreturnc URRU5nU(d#[R"SUS35 SSUS3S.$URR U5nU(d"[R "SUSS35 SSS.$[R "S USS [U5S 35 US nS n/n[R"5n[US5GHupU Sn U Sn [R "SU S[U5SU SU S3 5 URRU SUS3UUS9n U (do[R"SU S35 URU U S SSS.5 US:Xa[R "S5 OUS:Xa[R "S 5 OMURX5nURRU 5nURU U U UUR!S!5UR!S"5S#.5 US$;aX[R"S%U S&U35 US:Xa[R "S'5 O%US:Xa[R "S 5 OU nGM [R"5U- R#5n[%S(U55n['S)U55n[R "SUSS*US+S,[)S-U55S[U535 UUUS[U5[U5[)S.U55[)S/U55UUS0. $)1z Execute a job group with dependency chain Args: group_id: Job group ID to execute triggered_by: Who/what triggered execution Returns: Dictionary with execution results z Job group not foundF)successerrorz Job group 'namez' has no memberszNo jobs in groupz!Starting execution of job group 'z' (z jobs)error_handlingNjob_idjob_namezExecuting job /z: 'z' (ID )zgroup:)r!rrparent_execution_idzFailed to queue job ''failedzFailed to queue)r!r" execution_idstatusr stop_on_errorz-Stopping group execution due to queue failureskip_remainingz Skipping remaining jobs in groupduration_seconds exit_code)r!r"r(r)durationr-) completedJob 'z' ended with status: z%Stopping group execution due to errorc30# UH oSS:Hv M g7fr)r/N.0rs r 6DependencyManager.execute_job_group..|sR@Q1hK;6@Qc30# UH oSS;v M g7f)r)r'timeoutNr3r4s rr7r8}sYGX!8(==GXr9z' finished in z.1fzs - Completed: c3:# UHoSS:XdM Sv M g7fr)r/r Nr3r4s rr7r8s$`0A1x[T_E_QQ0A  c3:# UHoSS:XdM Sv M g7fr>r3r4s rr7r8s!]->H+Q\B\!!->r?c3:# UHoSS;dM Sv M g7f)r)r;r Nr3r4s rr7r8sd*;Q{Nc?cqq*;r?) rr group_name total_jobs executed_jobscompleted_jobs failed_jobsr, executions)r get_job_grouprrget_job_group_memberswarningrlenrnow enumerater execute_jobappend_wait_for_completion get_executionget total_secondsallanysum)rrrgroupmembersrr%execution_resultsgroup_start_timeimemberr!r"r( final_status executiongroup_duration all_completed any_faileds rexecute_job_group#DependencyManager.execute_job_groupsg%%h/ LL:hZz: ; %hZz:  ''//9 NN[v7GH I +   7f c#g,W]^_/0"#<<>"7A.IAH%Fj)H KK.1S\N#hZvfXUVW X ==44%eFm_5!$7 5L  4XJa@A!(($ ($(&. *"_4KK OP#'77KK BC 44\LL--l;I  $ $ $ ,&%MM*<=&]];7 & =0 uXJ.CL>RS!_4KK GH#'77KK BC#/ {/@#,,.+;;JJLR@QRR YGXYY  k%-~c>RS!!$$`0A$`!` aabcfgxcybz| }% -g, !23!!]->!]]d*;dd .+  rr(r" poll_intervalc[R"SUSUS35 URRU5nUS;a[R"SUSU35 U$[R "U5 MW)z Wait for job execution to complete Args: execution_id: Execution ID to monitor job_name: Job name for logging poll_interval: How often to check status (seconds) Returns: Final status ('completed', 'failed', 'timeout', 'cancelled') zWaiting for execution z ('z') to complete)r/r'r< cancelledz Execution z finished with status: )rdebugrget_execution_statustimesleep)rr(r"rdr)s rrP&DependencyManager._wait_for_completionsp  -l^3xjWXWW11,?FHH z,7NvhWX JJ} %rNrjob_ids descriptionrc`UH4nURRU5nU(aM'[SUS35e URRXU5n[ US5H!upURR XuU5 M# [ R"SUS[U5S35 U$)z Create a job group (chain) from a list of job IDs Args: name: Group name job_ids: List of job IDs in execution order description: Group description error_handling: 'stop_on_error', 'continue', or 'skip_remaining' Returns: Group ID Job ID rr zCreated job chain 'z' with z jobs) rget_job ValueErrorcreate_job_grouprMadd_job_to_grouprrrK) rrrlrmrr!jobrorders rcreate_job_chain"DependencyManager.create_job_chains F''//&)C3 76(*!=>> 77++D~N'w2ME GG $ $Xu =3  )$ws7|nEJKrlimitc lURR5nURSX45nUR5Vs/sHn[ U5PM nnSSS5 0nWH'nUSSSn X;a/Xy'XyR U5 M) /n [ UR5SS9Hqup[ U SS9n U S n U S nS nU HnUS (dMXS - nM [S U 55nU R U SUS U[U 5UU S.5 Ms U $s snf!,(df  N=f)z Get execution summary for a job group Args: group_id: Job group ID limit: Number of recent executions to retrieve Returns: List of execution summaries a  SELECT e.id, e.job_id, j.name as job_name, e.status, e.start_time, e.end_time, e.duration_seconds, e.exit_code, e.triggered_by FROM job_executions e JOIN jobs j ON e.job_id = j.id WHERE e.group_id = ? ORDER BY e.start_time DESC LIMIT ? N start_timeT)reversec US$)Nrzr3)xs r?DependencyManager.get_group_execution_summary..s1\?r)keyrr,c30# UH oSS:Hv M g7fr2r3)r5exs rr7@DependencyManager.get_group_execution_summary..sYFX8 ;FXr9end_time)rzrtotal_duration jobs_executedr`rG) r_get_connectionexecutefetchalldictrOsorteditemsrTrK)rrrxconncursorrowrGbatchesr start_key summaries batch_execsbatch_execs_sorted first_exec last_execrr`s rget_group_execution_summary-DependencyManager.get_group_execution_summarysgWW $ $ &$\\# "!$F$06/@A/@$s)/@JA'',B<("-I'%'"   % %b )   &,W]]_d&K "I!' 9R!S +A.J*2.IN(())");&<@C@@TRVWZ\_W_R`Ma@D% 3% 4S>% rr )rritypingrrrrrlogurur core.databaser daemon.job_executorr r r3rrrs-  ,,++] ] r