tx-agent-kit
Storage

Worker Activities

Temporal worker activities for background storage operations like cleanup and listing

The worker exposes storage activities for background processing tasks that should not block API requests. These activities are registered alongside the existing domain event activities in apps/worker/src/activities.ts.

Available activities

deleteStorageObjects

Batch-delete objects from R2. Processes each key individually and reports success/failure counts. A single failed deletion does not abort the batch.

const result = await deleteStorageObjects([
  'org-123/old-avatar.png',
  'org-123/temp-upload.jpg'
])
// { deleted: 2, failed: 0 }
FieldTypeDescription
keysReadonlyArray<string>Object keys to delete
Returns: deletednumberSuccessfully deleted count
Returns: failednumberFailed deletion count

listStorageObjects

List objects matching a prefix. Useful for finding orphaned files or building cleanup batches.

const keys = await listStorageObjects('org-123/')
// ['org-123/avatar.png', 'org-123/banner.jpg']
FieldTypeDescription
prefixstringKey prefix to filter by
ReturnsReadonlyArray<string>Matching object keys

Usage in workflows

Activities are called from Temporal workflows via proxyActivities:

import { proxyActivities } from '@temporalio/workflow'
import type { storageActivities } from './activities.js'

const { deleteStorageObjects, listStorageObjects } = proxyActivities<typeof storageActivities>({
  startToCloseTimeout: '60 seconds',
  retry: {
    maximumAttempts: 3,
    initialInterval: '2 seconds'
  }
})

export async function cleanupOrganizationFiles(orgId: string): Promise<void> {
  const keys = await listStorageObjects(`${orgId}/`)
  if (keys.length > 0) {
    await deleteStorageObjects(keys)
  }
}

Error handling

  • deleteStorageObjects catches errors per-key and logs failures. The activity itself does not throw unless every deletion fails.
  • listStorageObjects throws if the R2 API call fails, causing Temporal to retry per the workflow's retry policy.
PageDescription
Storage OverviewArchitecture and design decisions
Worker AppTemporal worker setup and activity registration

On this page