o ߺ2i@sjdZddlmZddlmZddlmZmZmZmZddl m Z ddl m Z ddl mZGdd d Zd S) zp Sync Module - Integration with Automation Daemon Manages sync operations, scheduling, and database integration )Path)datetime)DictAnyOptionalCallable)logger)Database) DirectorySyncc @steZdZdZdefddZ  ddedeedeed e e e ffd d Z ded ed e e e ffd dZ ddZdS) SyncModulezi Sync module for unified daemon Integrates DirectorySync with database and scheduling system dbcCs||_tddS)zm Initialize sync module Args: db: Database instance for CRUD operations zSyncModule initializedN)r rinfo)selfr r/c:\PYTHON\Scheduler\modules\sync\sync_module.py__init__szSyncModule.__init__N profile_id schedule_idprogress_callbackreturnc Cs|j|}|sd|d}t|d|dS|ds,d|d}t|d|dS|j|rCd|d}t|d|dd St}|jj|d |d }t d |d |d|dzkt |d|dd}|j |d} | drd} t | dd} td|dn d} d} t d|dt} |jj|| | | d| d| d| d| d d||| d| d| d| d| |d!d"WSty} z(t| }td|d#||jj|d$t|d%d|||d&WYd} ~ Sd} ~ ww)'aS Execute a sync operation Args: profile_id: Sync profile ID schedule_id: Optional schedule ID (when triggered by scheduler) progress_callback: Optional callback for progress updates Returns: Dict with operation results (success, operation_id, stats, error) z Sync profile z not foundF)successerrorenabledz is disabledz1 is already running - skipping to prevent overlapT)rrZskippedrunning)rstatus start_timezStarting sync operation z for profile z: name source_pathdestination_path)source destination)rerrorsZcompleted_with_errorsz error(s) occurredzSync operation z completed with errors completedNz completed successfully files_scanned files_copied files_deleted bytes_total) operation_idrend_timer#r$r%r& error_message)r#r$r%r&duration_seconds)rr'rstatsz failed: failed)r'rr(r))rr'rr)r get_sync_profilerrwarninghas_running_sync_operationrnowcreate_sync_operationr r syncgetlenupdate_sync_operation total_seconds Exceptionstr)rrrrprofile error_msgrr'Z sync_enginer+rr)r(errr execute_syncs                 zSyncModule.execute_sync target_idcCs(td|d||j||d}|S)a" Execute scheduled sync operation Called by daemon when a schedule triggers Args: schedule_id: Schedule ID that triggered target_id: Sync profile ID (from schedule.target_id) Returns: Dict with execution results z Schedule z triggered for sync profile )rr)rr r<)rrr=resultrrr schedule_items zSyncModule.schedule_itemcCstddS)zCleanup module resourceszSyncModule cleanup completedN)rr )rrrrcleanupszSyncModule.cleanup)NN)__name__ __module__ __qualname____doc__r rintrrrr8rr<r?r@rrrrr s    o r N)rDpathlibrrtypingrrrrlogurur core.databaser Zmodules.sync.sync_enginer r rrrrs