( lockDirPath: string, ownerFilePath: string, )
| 101 | } |
| 102 | |
| 103 | function readProcessLockDiagnostics( |
| 104 | lockDirPath: string, |
| 105 | ownerFilePath: string, |
| 106 | ): Record<string, unknown> { |
| 107 | const nowMs = Date.now(); |
| 108 | const owner = readProcessLockOwner(ownerFilePath); |
| 109 | let lockAgeMs: number | undefined; |
| 110 | try { |
| 111 | lockAgeMs = Math.max(0, Math.round(nowMs - fs.statSync(lockDirPath).mtimeMs)); |
| 112 | } catch {} |
| 113 | return { |
| 114 | ...(lockAgeMs !== undefined ? { lockAgeMs } : {}), |
| 115 | ...(owner |
| 116 | ? { |
| 117 | ownerPid: owner.pid, |
| 118 | ownerStartTime: owner.startTime, |
| 119 | ownerAgeMs: Math.max(0, Math.round(nowMs - owner.acquiredAtMs)), |
| 120 | } |
| 121 | : {}), |
| 122 | }; |
| 123 | } |
| 124 | |
| 125 | function isLiveProcessLockOwner(owner: ProcessLockOwner): boolean { |
| 126 | if (!Number.isInteger(owner.pid) || owner.pid <= 0) { |
no test coverage detected