Skip to main content

AsyncJobService

@webda/async


Class: AsyncJobService<T>

Defined in: packages/async/src/services/asyncjobservice.service.ts:162

AsyncService allows you to launch jobs and report status

Webda Modda​

Extends​

  • Service<T>

Type Parameters​

T​

T extends AsyncJobServiceParameters = AsyncJobServiceParameters

Implements​

  • RequestFilter<WebContext>

Constructors​

Constructor​

new AsyncJobService<T>(name, params): AsyncJobService<T>

Defined in: packages/core/lib/services/service.d.ts:72

Service

Parameters​

name​

string

The name of the service

params​

T

The parameters block define in the configuration file

Returns​

AsyncJobService<T>

Inherited from​

Service<T>.constructor

Properties​

_compiledCapabilities​

protected _compiledCapabilities: Record<string, any>

Defined in: packages/core/lib/services/iservice.d.ts:39

Capabilities detected at compile-time from @WebdaCapability-tagged interfaces.

Populated during Service.resolve by reading the service's entry in webda.module.json. Each key is a capability name (e.g., "request-filter"), and the value is an empty object {} by default. Override getCapabilities to provide capability-specific configuration or to conditionally disable capabilities.

See​

getCapabilities

Inherited from​

Service._compiledCapabilities


[WEBDA_EVENTS]​

[WEBDA_EVENTS]: object

Defined in: packages/core/lib/services/service.d.ts:50

Set the Webda events here

Inherited from​

Service.[WEBDA_EVENTS]


logger​

protected logger: Logger

Defined in: packages/core/lib/services/service.d.ts:59

Logger with class context

Inherited from​

Service.logger


metrics?​

protected optional metrics?: object

Defined in: packages/core/lib/services/service.d.ts:63

Get metrics

Inherited from​

Service.metrics


model​

model: (serviceName?, method?, ...args) => AsyncWebdaAction & ModelClass<AsyncWebdaAction>

Defined in: packages/async/src/services/asyncjobservice.service.ts:182

Model to use when launching action


name​

readonly name: string

Defined in: packages/core/lib/services/iservice.d.ts:19

Inherited from​

Service.name


operationModel​

operationModel: (operationId, context, logLevel?) => AsyncOperationAction

Defined in: packages/async/src/services/asyncjobservice.service.ts:187

Model to use when launching operation

Model to use when launching operation

Parameters​

operationId​

string

context​

OperationContext

logLevel?​

WorkerLogLevel

Returns​

AsyncOperationAction


operations​

protected operations: object

Defined in: packages/async/src/services/asyncjobservice.service.ts:195

Operations definition

application​

application: object

application.name​

name: string

application.version​

version: string

operations​

operations: object

Index Signature​

[key: string]: object

schemas​

schemas: object

Index Signature​

[key: string]: JSONSchema7


operationsQueries​

protected operationsQueries: object = {}

Defined in: packages/async/src/services/asyncjobservice.service.ts:203

Validator of sessions

Index Signature​

[key: string]: QueryValidator


parameters​

readonly parameters: T

Defined in: packages/core/lib/services/iservice.d.ts:20

Inherited from​

Service.parameters


queue​

protected queue: Queue<AsyncActionQueueItem>

Defined in: packages/async/src/services/asyncjobservice.service.ts:169

Queue for execution


runners​

protected runners: Runner<RunnerParameters>[]

Defined in: packages/async/src/services/asyncjobservice.service.ts:174

Runner to use


createConfiguration?​

static optional createConfiguration?: (params) => any

Defined in: packages/core/lib/services/iservice.d.ts:24

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

Service.createConfiguration


filterConfiguration?​

static optional filterConfiguration?: (params) => any

Defined in: packages/core/lib/services/iservice.d.ts:28

Create configuration set by the application on load

Parameters​

params​

any

Returns​

any

Inherited from​

Service.filterConfiguration


HMAC_ALGO​

static HMAC_ALGO: string = "sha256"

Defined in: packages/async/src/services/asyncjobservice.service.ts:178

HMAC Algorithm used for simple auth


Parameters​

static Parameters: typeof ServiceParameters

Defined in: packages/core/lib/services/service.d.ts:46

Service parameters

Inherited from​

Service.Parameters

Methods​

__clean()​

abstract __clean(): Promise<void>

Defined in: packages/core/lib/services/service.d.ts:215

Clean the service data, can only be used in test mode

Returns​

Promise<void>

Inherited from​

Service.__clean


addListener()​

addListener<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:80

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void | Promise<void>

the event listener

Returns​

this

this for chaining

See​

EventEmitter.addListener

Inherited from​

Service.addListener


addRoute()​

protected addRoute(url, methods, executer, openapi?, override?): void

Defined in: packages/core/lib/services/service.d.ts:177

Add a route dynamicaly

Parameters​

url​

string

of the route can contains dynamic part like {uuid}

methods​

HttpMethodType[]

the HTTP methods

executer​

Function

Method to execute for this route

openapi?​

OpenAPIWebdaDefinition

the OpenAPI specification

override?​

boolean

whether to override existing

Returns​

void

Inherited from​

Service.addRoute


authorizeClientEvent()​

authorizeClientEvent(_event, _context): boolean

Defined in: packages/core/lib/services/service.d.ts:153

Authorize a public event subscription

Parameters​

_event​

string

the event name

_context​

OperationContext

the execution context

Returns​

boolean

true if the condition is met

Inherited from​

Service.authorizeClientEvent


callOperation()​

callOperation(context): Promise<AsyncOperationAction>

Defined in: packages/async/src/services/asyncjobservice.service.ts:437

Call an operation for an external system

Parameters​

context​

OperationContext

the operation context

Returns​

Promise<AsyncOperationAction>

the launched action


checkOperation()​

checkOperation(context, operationId): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:446

Check the operation exists, is allowed and its input is valid

Parameters​

context​

OperationContext

the operation context

operationId​

string

the operation id

Returns​

Promise<void>


checkRequest()​

checkRequest(context): Promise<boolean>

Defined in: packages/async/src/services/asyncjobservice.service.ts:278

Allow job status report url

Parameters​

context​

WebContext

the web context

Returns​

Promise<boolean>

true if the request is a job status report

Implementation of​

RequestFilter.checkRequest


computeParameters()​

computeParameters(): void

Defined in: packages/core/lib/services/service.d.ts:77

Used to compute or derivate input parameter to attribute

Returns​

void

Deprecated​

Inherited from​

Service.computeParameters


emit()​

emit<Key>(event, data): Promise<void>

Defined in: packages/core/lib/services/service.d.ts:204

Emit the event with data and wait for Promise to finish if listener returned a Promise

Type Parameters​

Key​

Key extends never

Parameters​

event​

Key

the event name

data​

object[Key]

the data to process

Returns​

Promise<void>

Inherited from​

Service.emit


executeAsAsyncAction()​

executeAsAsyncAction(serviceName, method, ...args): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:581

Execute a service.method as an AsyncAction

Useful for crontab execution

Parameters​

serviceName​

string

the service

method​

string

the method

args​

...any[]

the arguments

Returns​

Promise<void>

the execution promise


getCapabilities()​

getCapabilities(): Record<string, any>

Defined in: packages/core/lib/services/iservice.d.ts:61

Return the capabilities of this service.

By default returns capabilities detected at compile-time from

Returns​

Record<string, any>

the result

Webda Capability-tagged​

interfaces in webda.module.json.

Override to disable capabilities based on configuration:

getCapabilities() {
const caps = super.getCapabilities();
if (!this.parameters.enabled) delete caps["request-filter"];
return caps;
}

Inherited from​

Service.getCapabilities


getClientEvents()​

getClientEvents(): string[]

Defined in: packages/core/lib/services/service.d.ts:144

Return the events that an external system can subscribe to

Returns​

string[]

the list of results

Inherited from​

Service.getClientEvents


getCronExecutor()​

getCronExecutor(cron): () => Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:678

Get the cron callback function

Parameters​

cron​

CronDefinition

the cron definition

Returns​

the cron callback

() => Promise<void>


getHeaders()​

getHeaders(jobInfo): object

Defined in: packages/async/src/services/asyncjobservice.service.ts:529

Return headers to request status hook

Parameters​

jobInfo​

JobInfo

the job information

Returns​

object

the headers


getHookUrl()​

getHookUrl(): string

Defined in: packages/async/src/services/asyncjobservice.service.ts:377

Absolute url of the status hook remote runners POST their reports to

It is this service status route: its request filter lets the job headers through and the HMAC is then verified by the action

Returns​

string

the hook url


getJobInfo()​

getJobInfo(action): JobInfo

Defined in: packages/async/src/services/asyncjobservice.service.ts:386

Get the job info

Parameters​

action​

AsyncAction

the action

Returns​

JobInfo

the job information


getMaxListeners()​

getMaxListeners(): number

Defined in: packages/core/lib/events/asynceventemitter.d.ts:84

Returns​

number

Inherited from​

Service.getMaxListeners


getMetric()​

getMetric<T>(type, configuration): T

Defined in: packages/core/lib/services/service.d.ts:138

Add service name label

Type Parameters​

T​

T = Gauge<string> | Counter<string> | Histogram<string>

Parameters​

type​

CustomConstructor<T, [MetricConfiguration<T>]>

the type to look up

configuration​

MetricConfiguration<T>

the configuration

Returns​

T

the result

Inherited from​

Service.getMetric


getName()​

getName(): string

Defined in: packages/core/lib/services/service.d.ts:209

Get service name

Returns​

string

the result string

Inherited from​

Service.getName


getOpenApiReplacements()​

getOpenApiReplacements(): any

Defined in: packages/core/lib/services/service.d.ts:182

Return variables for replacement in openapi

Returns​

any

the result

Inherited from​

Service.getOpenApiReplacements


getOperationId()​

getOperationId(id): string

Defined in: packages/core/lib/services/service.d.ts:167

If undefined is returned it cancel the operation registration

Parameters​

id​

string

the identifier

Returns​

string

the result

Inherited from​

Service.getOperationId


getParameters()​

getParameters(): T

Defined in: packages/core/lib/services/service.d.ts:82

Get the service parameters

Returns​

T

the result

Inherited from​

Service.getParameters


getService()​

getService<T>(name): ServicesMap[T]

Defined in: packages/core/lib/services/service.d.ts:131

Get a service by name

Type Parameters​

T​

T extends keyof ServicesMap

Parameters​

name​

T

the name to use

Returns​

ServicesMap[T]

the result map

Deprecated​

Use useService, might reconsider

Inherited from​

Service.getService


getState()​

getState(): ServiceStates

Defined in: packages/core/lib/services/service.d.ts:55

Get the current state

Returns​

ServiceStates

the result

Inherited from​

Service.getState


getUrl()​

getUrl(url, _methods): string

Defined in: packages/core/lib/services/service.d.ts:161

Return the full path url based on parameters

Parameters​

url​

string

relative url to service

_methods​

HttpMethodType[]

in case we need filtering (like Store)

Returns​

string

absolute url or undefined if need to skip the Route

Inherited from​

Service.getUrl


handleEvent()​

protected handleEvent(event): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:339

Handle one event from the queue and launch the job

Parameters​

event​

AsyncActionQueueItem

the queue item

Returns​

Promise<void>

the job promise if any


init()​

abstract init(): Promise<AsyncJobService<T>>

Defined in: packages/core/lib/services/service.d.ts:198

Will be called after all the Services are created

Returns​

Promise<AsyncJobService<T>>

Inherited from​

Service.init


initMetrics()​

initMetrics(): void

Defined in: packages/core/lib/services/service.d.ts:124

Init the metrics

Returns​

void

Inherited from​

Service.initMetrics


initOperations()​

initOperations(): void

Defined in: packages/core/lib/services/service.d.ts:186

Init the operations from

Returns​

void

Operation​

decorators on this service

Inherited from​

Service.initOperations


launchAction()​

launchAction<A>(action): Promise<A>

Defined in: packages/async/src/services/asyncjobservice.service.ts:492

Launch the action asynchronously

Type Parameters​

A​

A extends AsyncAction

Parameters​

action​

A

the action

Returns​

Promise<A>

the action


launchAsAsyncAction()​

launchAsAsyncAction(serviceName, method, ...args): Promise<AsyncWebdaAction>

Defined in: packages/async/src/services/asyncjobservice.service.ts:568

Launch a service.method as an AsyncAction

Parameters​

serviceName​

string

the service

method​

string

the method

args​

...any[]

the arguments

Returns​

Promise<AsyncWebdaAction>

the action


launchOperation()​

launchOperation(context): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:470

Launch an operation through this service

Parameters​

context​

WebContext

the web context

Returns​

Promise<void>


listeners()​

listeners(eventName): Function[]

Defined in: packages/core/lib/events/asynceventemitter.d.ts:139

Get all listeners for an event

Parameters​

eventName​

never

the event name

Returns​

Function[]

the list of results

Inherited from​

Service.listeners


listOperations()​

listOperations(context): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:399

List available operations through this service

Parameters​

context​

WebContext<void, { full?: boolean; }>

the web context

Returns​

Promise<void>


loadCapabilities()​

protected loadCapabilities(): void

Defined in: packages/core/lib/services/service.d.ts:120

Load capabilities from webda.module.json metadata into _compiledCapabilities.

Called during resolve after dependency injection. Reads the service's type name from parameters, looks it up in the application's module metadata (moddas or beans section), and populates _compiledCapabilities with an empty object for each declared capability name.

Fails silently if the application is not available (e.g., in unit tests where services are instantiated without a full application context).

Returns​

void

Example​

// If webda.module.json contains:
// { "moddas": { "MyApp/HawkService": { "capabilities": ["request-filter", "cors-filter"] } } }
// Then after resolve(), this.getCapabilities() returns:
// { "request-filter": {}, "cors-filter": {} }

See​

getCapabilities

Inherited from​

Service.loadCapabilities


log()​

log(level, ...args): void

Defined in: packages/core/lib/services/service.d.ts:226

Parameters​

level​

WorkerLogLevel

to log

args​

...any[]

additional arguments

Returns​

void

Inherited from​

Service.log


off()​

off<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:116

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.off

Inherited from​

Service.off


on()​

on<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:102

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

Service.on


once()​

once<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:95

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.once

Inherited from​

Service.once


postHook()​

postHook(jobInfo, message): Promise<AsyncWebdaAction>

Defined in: packages/async/src/services/asyncjobservice.service.ts:547

Post hook to a remote url or use local store to update status

Parameters​

jobInfo​

JobInfo

the job information

message​

any

the status report

Returns​

Promise<AsyncWebdaAction>

the updated action


registerOperations()​

registerOperations(operations): void

Defined in: packages/async/src/services/asyncjobservice.service.ts:247

Register new operations

Parameters​

operations​

the operations definition

application​

{ name: string; version: string; }

application.name​

string

application.version​

string

operations​

{[key: string]: object; }

schemas​

{[key: string]: JSONSchema7; }

Returns​

void


removeAllListeners()​

removeAllListeners<Key>(eventName?): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:122

Type Parameters​

Key​

Key extends never

Parameters​

eventName?​

Key

the event name

Returns​

this

this for chaining

See​

EventEmitter.removeAllListeners

Inherited from​

Service.removeAllListeners


removeListener()​

removeListener<Key>(eventName, listener): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:109

Type Parameters​

Key​

Key extends never

Parameters​

eventName​

Key

the event name

listener​

(event) => void

the event listener

Returns​

this

this for chaining

See​

EventEmitter.removeListener

Inherited from​

Service.removeListener


resolve()​

resolve(): this

Defined in: packages/async/src/services/asyncjobservice.service.ts:209

Returns​

this

this

Inherit Doc​

Overrides​

Service.resolve


runAction()​

runAction(): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:601

Run the AsyncAction described by the JOB_* environment variables

Returns​

Promise<void>

the execution promise


runAsyncOperationAction()​

runAsyncOperationAction(jobInfo?): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:610

Wrap async job and call the job status hook

Parameters​

jobInfo?​

JobInfo

the job information, from environment if not provided

Returns​

Promise<void>

a promise resolved once the job is reported


scheduleAction()​

scheduleAction<A>(action, timestamp): Promise<A>

Defined in: packages/async/src/services/asyncjobservice.service.ts:514

Schedule action for later execution

Type Parameters​

A​

A extends AsyncAction

Parameters​

action​

A

the action

timestamp​

number

when to launch it

Returns​

Promise<A>

the action


scheduler()​

scheduler(): CancelableLoopPromise

Defined in: packages/async/src/services/asyncjobservice.service.ts:700

Manage scheduled actions and crontab actions

Returns​

CancelableLoopPromise

a cancelable loop promise


setMaxListeners()​

setMaxListeners(n): this

Defined in: packages/core/lib/events/asynceventemitter.d.ts:88

Parameters​

n​

number

Returns​

this

Inherited from​

Service.setMaxListeners


statusHook()​

protected statusHook(context): Promise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:295

Status hook for job report

Only updates specific fields: status, errorMessage, statusDetails, results, logs (appending)

Parameters​

context​

WebContext

the web context

Returns​

Promise<void>


stop()​

stop(): Promise<void>

Defined in: packages/core/lib/services/service.d.ts:86

Shutdown the current service if action need to be taken

Returns​

Promise<void>

Inherited from​

Service.stop


toJSON()​

toJSON(): string

Defined in: packages/core/lib/services/service.d.ts:191

Prevent service to be serialized

Returns​

string

the result

Inherited from​

Service.toJSON


toString()​

toString(): string

Defined in: packages/core/lib/services/service.d.ts:91

Return service representation

Returns​

string

the result

Inherited from​

Service.toString


worker()​

worker(): CancelablePromise<void>

Defined in: packages/async/src/services/asyncjobservice.service.ts:314

Worker

This will launch actions based on defined runners

Returns​

CancelablePromise<void>

a cancelable promise