Hi, i’m currently developing a worker to deploy on my infra, the problem im having is that the worker is detected by the cloud, but no work is ever done, not even a failure state, heres what apears on the cloud:
The console output after a couple of minutes of the workflow being started
ill attach some of my source code
apps/worker/src/index.ts
import { NativeConnection, Worker } from '@temporalio/worker'
import { TEMPORAL_NAMESPACE, TEMPORAL_TASK_QUEUE } from '@/common/constants'
import { createNestApp } from '@/api/nest/app.module'
import * as activities from '@/api/worker/activities'
import { getConnectionOptions } from '@/api/worker/utils'
import { ScheduleService } from '@/api/nest/temporal/schedules/application/schedules.service'
async function createWorkers(connection: NativeConnection): Promise<void> {
try {
const workflowsPath = require.resolve('@/api/worker/workflows/index.ts')
const worker = await Worker.create({
workflowsPath,
activities,
connection,
namespace: TEMPORAL_NAMESPACE,
taskQueue: TEMPORAL_TASK_QUEUE,
})
await worker.run()
} catch (error) {
console.error('Unexpected error in main process', error)
throw error
}
}
async function run(): Promise<void> {
const app = await createNestApp({ isSuperUser: true })
const scheduleService = app.get(ScheduleService)
await scheduleService.createOrUpdateAllScheduledWorkflows()
const connection = await NativeConnection.connect(getConnectionOptions())
while (true) {
try {
await createWorkers(connection)
} catch (error) {
throw error
}
}
}
run().catch(async (error) => {
console.error('Unexpected error in main process', error)
})
packages/api/worker/utils.ts
import isNil from 'lodash.isnil'
import {
TEMPORAL_CLOUD_CERT,
TEMPORAL_CLOUD_KEY,
TEMPORAL_ADDRESS,
TEMPORAL_API_KEY,
} from '@/common/constants'
interface ConnectionOptions {
address: string
tls?: { clientCertPair: { crt: Buffer; key: Buffer } }
apiKey?: string
}
export function getConnectionOptions(): ConnectionOptions {
return {
address: TEMPORAL_ADDRESS || '',
apiKey: TEMPORAL_API_KEY || '',
...(!isNil(TEMPORAL_CLOUD_CERT) && !isNil(TEMPORAL_CLOUD_KEY)
? {
tls: {
clientCertPair: {
crt: Buffer.from(TEMPORAL_CLOUD_CERT),
key: Buffer.from(TEMPORAL_CLOUD_KEY),
},
},
}
: {}),
}
}
packages/api/worker/activities/hello-world.activity.ts
import { withNest } from '@/api/nest/app.module'
import { INestApplicationContext } from '@nestjs/common'
export const helloWorldActivity = withNest(
async (app: INestApplicationContext): Promise<string> => {
return 'Hello World from Activity!'
},
)
packages/api/worker/activities/index.ts
export { helloWorldActivity } from './hello-world.activity'
packages/api/worker/workflows/hello-world.workflow.ts
import acts from '@/api/worker/workflows/proxy-activities'
export async function helloWorldWorkflow(): Promise<string> {
return acts.helloWorldActivity()
}
helloWorldWorkflow.workflowName = 'helloWorldWorkflow'
packages/api/worker/workflows/proxy-activities.ts
import type { ActivityOptions } from '@temporalio/workflow'
import { proxyActivities } from '@temporalio/workflow'
import type * as activities from '@/api/worker/activities'
// Needs to be in same directory as workflows
// Workflows has issues with aliased imports
const DEFAULT_CONFIG = {
startToCloseTimeout: '1 minute',
scheduleToStartTimeout: '1 minute',
retry: {
initialInterval: '1s',
maximumInterval: '1m',
maximumAttempts: 3,
},
} satisfies ActivityOptions
export const getActivities = (config: ActivityOptions = DEFAULT_CONFIG): typeof activities => {
return proxyActivities<typeof activities>(config)
}
export default getActivities()
packages/api/worker/workflows/index.ts
// Export all workflows
export { helloWorldWorkflow } from './hello-world.workflow'
and finally, the withNest function
packages/api/nest/app.module.ts
export function withNest<T extends any[], R>(
fn: (app: INestApplicationContext, ...args: T) => Promise<R>,
): (...args: T) => Promise<R> {
return async function (...args: T): Promise<R> {
const app = await createNestApp({ isSuperUser: true })
try {
return await fn(app, ...args)
} finally {
await app.close()
}
}
}
All of my envs are correct, i generated the TLS certificates using the tcld CLI app.
Any help would be appreciated, im baging my head against my desk rn.


