FaasJS
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security
Home
  • Guide
  • Documents
  • Templates
  • Changelog
  • Ecosystem

    • Docker Images
  • Github
  • Contributing
  • Sponsor
  • Security

Documents / @faasjs/jobs / Job

Class: Job<TSchema, TContext, TResult>

Executable job definition returned by defineJob.

Extends

  • Func<JobEvent<TSchema>, TContext, TResult>

Type Parameters

TSchema

TSchema extends ZodType | undefined = undefined

TContext

TContext = any

TResult

TResult = any

Indexable

[key: string]: any

Constructors

Constructor

new Job<TSchema, TContext, TResult>(options): Job<TSchema, TContext, TResult>

Parameters

options

DefineJobOptions<TSchema, TContext, TResult>

Returns

Job<TSchema, TContext, TResult>

Overrides

Func<JobEvent<TSchema>, TContext, TResult>.constructor

Methods

export()

export(): object

Build the exported handler wrapper for the function.

The wrapper initializes request id/runtime context fields, invokes mount hooks on first use, and throws any Error object stored in data.response.

Returns

object

Object containing the exported handler.

handler

handler: ExportedHandler<JobEvent<TSchema>, TContext, TResult>

Inherited from

Func.export

invoke()

invoke(data): Promise<void>

Invoke the function.

Parameters

data

InvokeData<JobEvent<TSchema>, TContext, TResult>

Invocation state mutated by plugins and the final handler.

Returns

Promise<void>

Promise that resolves after invoke hooks complete.

Inherited from

Func.invoke

mount()

mount(data?): Promise<void>

First time mount the function.

Parameters

data?

Optional initial event, context, config, and logger used during mount.

config?

Config

Function config override used during mount.

context

TContext

Initial context value passed through mount hooks.

event

JobEvent

Initial event value passed through mount hooks.

logger?

Logger

Logger override used during mount.

Returns

Promise<void>

Promise that resolves after mount hooks complete.

Inherited from

Func.mount

Properties

__faasjsJob

readonly __faasjsJob: true = true

Internal

Marker used by the job loader to recognize job definitions.

config

config: Config

Mutable runtime configuration used by the function.

Inherited from

Func.config

cron

readonly cron: JobCron<SchemaOutput<TSchema, Record<string, never>>>[]

Cron rules used by JobScheduler to enqueue scheduled jobs.

filename?

optional filename?: string

Resolved source filename inferred from the constructor call stack.

Inherited from

Func.filename

handler?

optional handler?: Handler<JobEvent<TSchema>, TContext, TResult>

Final business handler invoked after plugins finish.

Inherited from

Func.handler

maxAttempts

readonly maxAttempts: number

Normalized maximum attempts before a job is marked failed.

mounted

mounted: boolean = false

Indicates whether mount hooks have already run.

Inherited from

Func.mounted

plugins

plugins: Plugin[]

Ordered plugin instances attached to this function.

Inherited from

Func.plugins

queue

readonly queue: string

Normalized queue name used by default enqueues and workers.

retry

readonly retry: JobRetry | undefined

Retry strategy used after failed attempts.

runtime

runtime: FuncRuntime | undefined

Default runtime value written to context.runtime when the caller does not provide one.

Inherited from

Func.runtime

schema

readonly schema: TSchema | undefined

Zod schema used to validate job params before the handler runs.