()
| 233 | } |
| 234 | |
| 235 | private async getClient(): Promise<WorkflowClient> { |
| 236 | if (this.clientPromise) { |
| 237 | return this.clientPromise; |
| 238 | } |
| 239 | |
| 240 | this.clientPromise = (async () => { |
| 241 | try { |
| 242 | this.logger.log(`Connecting to Temporal at ${this.address} (namespace=${this.namespace})`); |
| 243 | const connection = await Connection.connect({ address: this.address }); |
| 244 | await this.ensureNamespace(connection); |
| 245 | this.connection = connection; |
| 246 | const client = new WorkflowClient({ |
| 247 | connection, |
| 248 | namespace: this.namespace, |
| 249 | }); |
| 250 | this.logger.log( |
| 251 | `Temporal client ready (namespace=${this.namespace}, defaultTaskQueue=${this.defaultTaskQueue})`, |
| 252 | ); |
| 253 | return client; |
| 254 | } catch (error) { |
| 255 | this.clientPromise = undefined; |
| 256 | this.logger.error( |
| 257 | `Failed to connect to Temporal: ${ |
| 258 | error instanceof Error ? error.message : String(error) |
| 259 | }`, |
| 260 | ); |
| 261 | throw error; |
| 262 | } |
| 263 | })(); |
| 264 | |
| 265 | return this.clientPromise; |
| 266 | } |
| 267 | |
| 268 | private async ensureNamespace(connection: Connection): Promise<void> { |
| 269 | try { |
no test coverage detected