AsyncJobService
Class: AsyncJobService<T>
Defined in: packages/async/src/services/asyncjobservice.service.ts:185
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
Create a new Service instance
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:50
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
protectedlogger:Logger
Defined in: packages/core/lib/services/service.d.ts:59
Logger with class context
Inherited from
Service.logger
metrics?
protectedoptionalmetrics?:object
Defined in: packages/core/lib/services/service.d.ts:63
Get metrics
Inherited from
Service.metrics
model
model: (new (
serviceName?,method?, ...args) =>AsyncWebdaAction) &ModelClass<AsyncWebdaAction>
Defined in: packages/async/src/services/asyncjobservice.service.ts:205
Model to use when launching action
name
readonlyname:string
Defined in: packages/core/lib/services/iservice.d.ts:27
Name
Inherited from
Service.name
operationModel?
optionaloperationModel?: new (operationId,context,logLevel?) =>AsyncOperationAction
Defined in: packages/async/src/services/asyncjobservice.service.ts:210
Model to use when launching operation
Model to use when launching operation
Parameters
operationId
string
context
OperationContext
logLevel?
WorkerLogLevel
Returns
operations
protectedoperations:object
Defined in: packages/async/src/services/asyncjobservice.service.ts:218
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
protectedoperationsQueries:object={}
Defined in: packages/async/src/services/asyncjobservice.service.ts:226
Validator of sessions
Index Signature
[key: string]: QueryValidator
parameters
readonlyparameters:T
Defined in: packages/core/lib/services/iservice.d.ts:31
Parameters
Inherited from
Service.parameters
queue?
protectedoptionalqueue?:Queue<AsyncActionQueueItem,QueueParameters>
Defined in: packages/async/src/services/asyncjobservice.service.ts:192
Queue for execution
runners
protectedrunners:Runner<RunnerParameters>[]
Defined in: packages/async/src/services/asyncjobservice.service.ts:197
Runner to use
createConfiguration?
staticoptionalcreateConfiguration?: (params) =>any
Defined in: packages/core/lib/services/iservice.d.ts:35
Create configuration set by the application on load
Parameters
params
any
Returns
any
Inherited from
Service.createConfiguration
filterConfiguration?
staticoptionalfilterConfiguration?: (params) =>any
Defined in: packages/core/lib/services/iservice.d.ts:39
Create configuration set by the application on load
Parameters
params
any
Returns
any
Inherited from
Service.filterConfiguration
HMAC_ALGO
staticHMAC_ALGO:string="sha256"
Defined in: packages/async/src/services/asyncjobservice.service.ts:201
HMAC Algorithm used for simple auth
Parameters
staticParameters: typeofServiceParameters
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:224
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:87
Add listener
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()
protectedaddRoute(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:468
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:478
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:304
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:213
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:627
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:72
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:734
Get the cron callback function
Each tick launches the cron operation as an AsyncOperationAction, called as the system with the cron input
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:574
Return headers to request status hook
Parameters
jobInfo
the job information
Returns
object
the headers
getHookUrl()
getHookUrl():
string
Defined in: packages/async/src/services/asyncjobservice.service.ts:408
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:417
Get the job info
Parameters
action
the action
Returns
the job information
getMaxListeners()
getMaxListeners():
number
Defined in: packages/core/lib/events/asynceventemitter.d.ts:91
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:218
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|undefined
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 | undefined
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()
protectedhandleEvent(event):Promise<void>
Defined in: packages/async/src/services/asyncjobservice.service.ts:365
Handle one event from the queue and launch the job
Parameters
event
the queue item
Returns
Promise<void>
the job promise if any
init()
abstractinit():Promise<AsyncJobService<T>>
Defined in: packages/core/lib/services/service.d.ts:207
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:195
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:536
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:614
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:513
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:151
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:430
List available operations through this service
Parameters
context
WebContext<void, { full?: boolean; }>
the web context
Returns
Promise<void>
loadCapabilities()
protectedloadCapabilities():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:236
Log operation
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:127
Perform off
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:111
Perform on
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:103
Perform once
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
operationSchemaName()
protectedoperationSchemaName(method,side):string
Defined in: packages/core/lib/services/service.d.ts:191
Schema of an operation side: <service name>.<method>.<side> when the application knows it, else the one the
build writes, <class>.<method>.<side>, for the class or its nearest ancestor that has it (a service configured
under another name than its class)
Parameters
method
string
the method name
side
"input" | "output"
input or output
Returns
string
the schema name
Inherited from
Service.operationSchemaName
postHook()
postHook(
jobInfo,message):Promise<AsyncOperationAction|AsyncWebdaAction>
Defined in: packages/async/src/services/asyncjobservice.service.ts:592
Post hook to a remote url or use local store to update status
Parameters
jobInfo
the job information
message
any
the status report
Returns
Promise<AsyncOperationAction | AsyncWebdaAction>
the updated action
registerOperations()
registerOperations(
operations):void
Defined in: packages/async/src/services/asyncjobservice.service.ts:273
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:134
Remove all listeners
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:119
Remove listener
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:233
Resolve operation
Returns
this
this
Inherit Doc
Overrides
Service.resolve
runAction()
runAction():
Promise<void>
Defined in: packages/async/src/services/asyncjobservice.service.ts:647
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:656
Wrap async job and call the job status hook
Parameters
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:558
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:753
Manage scheduled actions and crontab actions
The crons are scheduled on the cluster leader only: each tick launches one action across the replicas
Returns
CancelableLoopPromise
a cancelable loop promise
setMaxListeners()
setMaxListeners(
n):this
Defined in: packages/core/lib/events/asynceventemitter.d.ts:95
Parameters
n
number
Returns
this
Inherited from
Service.setMaxListeners
statusHook()
protectedstatusHook(context):Promise<void>
Defined in: packages/async/src/services/asyncjobservice.service.ts:321
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:200
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:340
Worker
This will launch actions based on defined runners
Returns
CancelablePromise<void>
a cancelable promise