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.eventsevent 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
Returns void
externalon
Parameters
externalevent: EventTypeName
externallistener: (...args) => 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:voidEmitted 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:voidWhen 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 theabortingevent 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 themigratingevent, in which case theisMigratingflag is set totrue. Otherwise the flag isfalse. Note that thepersistStateevent is provided merely for user convenience, you can achieve the same effect usingsetInterval()and listening for themigratingevent.