PlatformEventManager
Hierarchy
- EventManager
- PlatformEventManager
Index
Constructors
constructor
Parameters
config: Configuration = ...
Returns PlatformEventManager
Properties
readonlyconfig
Methods
close
Closes websocket providing events from Actor infrastructure and also stops sending internal events of Apify package such as
persistState
. This is automatically called at the end ofActor.main()
.Returns Promise<void>
externalemit
Parameters
externalevent: EventTypeName
externalrest...args: unknown[]
Returns void
init
Initializes
Actor.events
event emitter by creating a connection to a websocket that provides them. This is an internal function that is automatically called byActor.main()
.Returns Promise<void>
externalisInitialized
Returns boolean
externaloff
Parameters
externalevent: EventTypeName
externaloptionallistener: (...args: any[]) => any
Returns void
externalon
Parameters
externalevent: EventTypeName
externallistener: (...args: any[]) => any
Returns void
Gets an instance of a Node.js' EventEmitter class that emits various events from the SDK or the Apify platform. The event emitter is initialized by calling the Actor.main function.
Example usage:
The following events are emitted:
cpuInfo
:{ "isCpuOverloaded": Boolean }
The event is emitted approximately every second and it indicates whether the actor is using the maximum of available CPU resources. If that's the case, the actor should not add more workload. For example, this event is used by the AutoscaledPool class.migrating
:void
Emitted when the actor running on the Apify platform is going to be migrated to another worker server soon. You can use it to persist the state of the actor and gracefully stop your in-progress tasks, so that they are not interrupted by the migration. For example, this is used by the RequestList class.aborting
:void
When a user aborts an actor run on the Apify platform, they can choose to abort gracefully to allow the actor some time before getting killed. This graceful abort emits theaborting
event which the SDK uses to gracefully stop running crawls and you can use it to do your own cleanup as well.persistState
:{ "isMigrating": Boolean }
Emitted in regular intervals (by default 60 seconds) to notify all components of Apify SDK that it is time to persist their state, in order to avoid repeating all work when the actor restarts. This event is automatically emitted together with themigrating
event, in which case theisMigrating
flag is set totrue
. Otherwise the flag isfalse
. Note that thepersistState
event is provided merely for user convenience, you can achieve the same effect usingsetInterval()
and listening for themigrating
event.