1- import { syncPeachRecords } from './src/controllers /peach.ts' ;
2- import { sendPermitUpdateNotifications } from './src/controllers /permit.ts' ;
1+ import { syncPeachRecords } from './src/domains /peach.ts' ;
2+ import { sendPermitUpdateNotifications } from './src/domains /permit.ts' ;
33import { refreshCodeCaches } from './src/db/codes/cache.ts' ;
4+ import { unitOfWork } from './src/db/unitOfWork.ts' ;
45import { getLogger } from './src/utils/log.ts' ;
56import { state } from './state.ts' ;
67
@@ -11,33 +12,42 @@ const log = getLogger(module.filename);
1112async function syncPeachToPcns ( ) {
1213 if ( ! state . features . peach ) return ;
1314
14- const started = Date . now ( ) ;
15- let updatedPermitsWithNotes : UpdatedPermitWithNote [ ] ;
15+ await unitOfWork . execute (
16+ async ( { electrificationProject, generalProject, housingProject, permit, permitNote, user } ) => {
17+ const started = Date . now ( ) ;
18+ let updatedPermitsWithNotes : UpdatedPermitWithNote [ ] ;
1619
17- log . info ( 'PEACH sync job started' ) ;
18- try {
19- updatedPermitsWithNotes = await syncPeachRecords ( ) ;
20+ log . info ( 'PEACH sync job started' ) ;
21+ try {
22+ updatedPermitsWithNotes = await syncPeachRecords ( { permit } ) ;
2023
21- log . info ( 'PEACH sync completed' , {
22- durationMs : Date . now ( ) - started ,
23- updatedCount : updatedPermitsWithNotes . length
24- } ) ;
25- } catch ( error ) {
26- log . error ( 'PEACH sync FAILED during data sync' , error ) ;
27- process . exitCode = 1 ;
28- return ;
29- }
24+ log . info ( 'PEACH sync completed' , {
25+ durationMs : Date . now ( ) - started ,
26+ updatedCount : updatedPermitsWithNotes . length
27+ } ) ;
28+ } catch ( error ) {
29+ log . error ( 'PEACH sync FAILED during data sync' , error ) ;
30+ process . exitCode = 1 ;
31+ return ;
32+ }
3033
31- if ( updatedPermitsWithNotes . length === 0 ) return ;
34+ if ( updatedPermitsWithNotes . length === 0 ) return ;
3235
33- try {
34- for ( const permitWithNote of updatedPermitsWithNotes ) {
35- const { permit, note } = permitWithNote ;
36- await sendPermitUpdateNotifications ( permit , true , note ) ;
36+ try {
37+ for ( const permitWithNote of updatedPermitsWithNotes ) {
38+ const { permit, note } = permitWithNote ;
39+ await sendPermitUpdateNotifications (
40+ { electrificationProject, generalProject, housingProject, permitNote, user } ,
41+ permit ,
42+ true ,
43+ note
44+ ) ;
45+ }
46+ } catch ( error ) {
47+ log . warn ( 'PEACH sync completed but sending notifications failed' , error ) ;
48+ }
3749 }
38- } catch ( error ) {
39- log . warn ( 'PEACH sync completed but sending notifications failed' , error ) ;
40- }
50+ ) ;
4151}
4252
4353async function main ( ) {
0 commit comments