Skip to content

FluxbaseAdminJobs

Admin Jobs manager for managing background job functions Provides create, update, delete, sync, and monitoring operations

new FluxbaseAdminJobs(fetch): FluxbaseAdminJobs

ParameterType
fetchFluxbaseFetch

FluxbaseAdminJobs

cancel(jobId): Promise<object>

Cancel a running or pending job

ParameterTypeDescription
jobIdstringJob ID

Promise<object>

Promise resolving to { data, error } tuple

NameType
datanull
errornull | Error
const { data, error } = await client.admin.jobs.cancel('550e8400-e29b-41d4-a716-446655440000')

create(request): Promise<object>

Create a new job function

ParameterTypeDescription
requestCreateJobFunctionRequestJob function configuration and code

Promise<object>

Promise resolving to { data, error } tuple with created job function metadata

NameType
datanull | JobFunction
errornull | Error
const { data, error } = await client.admin.jobs.create({
name: 'process-data',
code: 'export async function handler(req) { return { success: true } }',
enabled: true,
timeout_seconds: 300
})

delete(namespace, name): Promise<object>

Delete a job function

ParameterTypeDescription
namespacestringNamespace
namestringJob function name

Promise<object>

Promise resolving to { data, error } tuple

NameType
datanull
errornull | Error
const { data, error } = await client.admin.jobs.delete('default', 'process-data')

get(namespace, name): Promise<object>

Get details of a specific job function

ParameterTypeDescription
namespacestringNamespace
namestringJob function name

Promise<object>

Promise resolving to { data, error } tuple with job function metadata

NameType
datanull | JobFunction
errornull | Error
const { data, error } = await client.admin.jobs.get('default', 'process-data')
if (data) {
console.log('Job function version:', data.version)
}

getJob(jobId): Promise<object>

Get details of a specific job (execution)

ParameterTypeDescription
jobIdstringJob ID

Promise<object>

Promise resolving to { data, error } tuple with job details

NameType
datanull | Job
errornull | Error
const { data, error } = await client.admin.jobs.getJob('550e8400-e29b-41d4-a716-446655440000')
if (data) {
console.log(`Job ${data.job_name}: ${data.status}`)
}

getStats(namespace?): Promise<object>

Get job statistics

ParameterTypeDescription
namespace?stringOptional namespace filter

Promise<object>

Promise resolving to { data, error } tuple with job stats

NameType
datanull | JobStats
errornull | Error
const { data, error } = await client.admin.jobs.getStats('default')
if (data) {
console.log(`Pending: ${data.pending}, Running: ${data.running}`)
}

list(namespace?): Promise<object>

List all job functions (admin view)

ParameterTypeDescription
namespace?stringOptional namespace filter

Promise<object>

Promise resolving to { data, error } tuple with array of job functions

NameType
datanull | JobFunction[]
errornull | Error
const { data, error } = await client.admin.jobs.list('default')
if (data) {
console.log('Job functions:', data.map(f => f.name))
}

listJobs(filters?): Promise<object>

List all jobs (executions) across all namespaces (admin view)

ParameterTypeDescription
filters?objectOptional filters (status, namespace, limit, offset)
filters.includeResult?boolean-
filters.limit?number-
filters.namespace?string-
filters.offset?number-
filters.status?string-

Promise<object>

Promise resolving to { data, error } tuple with array of jobs

NameType
datanull | Job[]
errornull | Error
const { data, error } = await client.admin.jobs.listJobs({
status: 'running',
namespace: 'default',
limit: 50
})
if (data) {
data.forEach(job => {
console.log(`${job.job_name}: ${job.status}`)
})
}

listNamespaces(): Promise<object>

List all namespaces that have job functions

Promise<object>

Promise resolving to { data, error } tuple with array of namespace strings

NameType
datanull | string[]
errornull | Error
const { data, error } = await client.admin.jobs.listNamespaces()
if (data) {
console.log('Available namespaces:', data)
}

listWorkers(): Promise<object>

List active workers

Promise<object>

Promise resolving to { data, error } tuple with array of workers

NameType
datanull | JobWorker[]
errornull | Error
const { data, error } = await client.admin.jobs.listWorkers()
if (data) {
data.forEach(worker => {
console.log(`Worker ${worker.id}: ${worker.current_jobs} jobs`)
})
}

retry(jobId): Promise<object>

Retry a failed job

ParameterTypeDescription
jobIdstringJob ID

Promise<object>

Promise resolving to { data, error } tuple with new job

NameType
datanull | Job
errornull | Error
const { data, error } = await client.admin.jobs.retry('550e8400-e29b-41d4-a716-446655440000')

sync(options): Promise<object>

Sync multiple job functions to a namespace

Can sync from:

  1. Filesystem (if no jobs provided) - loads from configured jobs directory
  2. API payload (if jobs array provided) - syncs provided job specifications

Requires service_role or admin authentication.

ParameterTypeDescription
optionsstring | SyncJobsOptionsSync options including namespace and optional jobs array

Promise<object>

Promise resolving to { data, error } tuple with sync results

NameType
datanull | SyncJobsResult
errornull | Error
// Sync from filesystem
const { data, error } = await client.admin.jobs.sync({ namespace: 'default' })
// Sync with pre-bundled code (client-side bundling)
const bundled = await FluxbaseAdminJobs.bundleCode({ code: myJobCode })
const { data, error } = await client.admin.jobs.sync({
namespace: 'default',
functions: [{
name: 'my-job',
code: bundled.code,
is_pre_bundled: true,
original_code: myJobCode,
}],
options: {
delete_missing: true, // Remove jobs not in this sync
dry_run: false, // Preview changes without applying
}
})
if (data) {
console.log(`Synced: ${data.summary.created} created, ${data.summary.updated} updated`)
}

syncWithBundling(options, bundleOptions?): Promise<object>

Sync job functions with automatic client-side bundling

This is a convenience method that bundles all job code using esbuild before sending to the server. Requires esbuild as a peer dependency.

ParameterTypeDescription
optionsSyncJobsOptionsSync options including namespace and jobs array
bundleOptions?Partial<BundleOptions>Optional bundling configuration

Promise<object>

Promise resolving to { data, error } tuple with sync results

NameType
datanull | SyncJobsResult
errornull | Error
const { data, error } = await client.admin.jobs.syncWithBundling({
namespace: 'default',
functions: [
{ name: 'process-data', code: processDataCode },
{ name: 'send-email', code: sendEmailCode },
],
options: { delete_missing: true }
})

terminate(jobId): Promise<object>

Terminate a running job immediately

ParameterTypeDescription
jobIdstringJob ID

Promise<object>

Promise resolving to { data, error } tuple

NameType
datanull
errornull | Error
const { data, error } = await client.admin.jobs.terminate('550e8400-e29b-41d4-a716-446655440000')

update(namespace, name, updates): Promise<object>

Update an existing job function

ParameterTypeDescription
namespacestringNamespace
namestringJob function name
updatesUpdateJobFunctionRequestFields to update

Promise<object>

Promise resolving to { data, error } tuple with updated job function metadata

NameType
datanull | JobFunction
errornull | Error
const { data, error } = await client.admin.jobs.update('default', 'process-data', {
enabled: false,
timeout_seconds: 600
})

static bundleCode(options): Promise<BundleResult>

Bundle job code using esbuild (client-side)

Transforms and bundles TypeScript/JavaScript code into a single file that can be executed by the Fluxbase jobs runtime.

Requires esbuild as a peer dependency.

ParameterTypeDescription
optionsBundleOptionsBundle options including source code

Promise<BundleResult>

Promise resolving to bundled code

Error if esbuild is not available

const bundled = await FluxbaseAdminJobs.bundleCode({
code: `
import { helper } from './utils'
export async function handler(req) {
return helper(req.payload)
}
`,
minify: true,
})
// Use bundled code in sync
await client.admin.jobs.sync({
namespace: 'default',
functions: [{
name: 'my-job',
code: bundled.code,
is_pre_bundled: true,
}]
})