()
| 116 | } |
| 117 | |
| 118 | async function main() { |
| 119 | const pool = new Pool({ connectionString: DATABASE_URL }); |
| 120 | const connection = await Connection.connect({ address: TEMPORAL_ADDRESS }); |
| 121 | const client = new Client({ connection, namespace: TEMPORAL_NAMESPACE }); |
| 122 | |
| 123 | try { |
| 124 | const runId = `long-lived-${randomUUID()}`; |
| 125 | console.log(`Starting long-lived workflow ${runId}`); |
| 126 | const start = Date.now(); |
| 127 | |
| 128 | const handle = await client.workflow.start(shipsecWorkflowRun, { |
| 129 | workflowId: runId, |
| 130 | taskQueue: TEMPORAL_TASK_QUEUE, |
| 131 | args: [ |
| 132 | { |
| 133 | runId, |
| 134 | workflowId: 'long-lived-synthetic', |
| 135 | definition: longLivedDefinition, |
| 136 | inputs: {}, |
| 137 | }, |
| 138 | ], |
| 139 | }); |
| 140 | |
| 141 | const result = await handle.result(); |
| 142 | const durationMs = Date.now() - start; |
| 143 | console.log(`Workflow completed in ${durationMs}ms`); |
| 144 | |
| 145 | const traces = await collectTraces(pool, runId); |
| 146 | await ensureOutputDir(); |
| 147 | const snapshotPath = join(OUTPUT_DIR, `long-lived-trace-${runId}.json`); |
| 148 | await fs.writeFile( |
| 149 | snapshotPath, |
| 150 | JSON.stringify({ runId, durationMs, completed: result, traces }, null, 2), |
| 151 | 'utf8', |
| 152 | ); |
| 153 | |
| 154 | console.log(`Trace snapshot written to ${snapshotPath}`); |
| 155 | console.log(`Trace events captured: ${traces.length}`); |
| 156 | } finally { |
| 157 | await client.connection.close(); |
| 158 | await pool.end(); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if (import.meta.main) { |
| 163 | main().catch((err) => { |
no test coverage detected