Skip to main content
Version: 3.0


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:

Actor.on('cpuInfo', (data) => {
if (data.isCpuOverloaded) console.log('Oh no, the CPU is overloaded!');

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 the aborting 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 the migrating event, in which case the isMigrating flag is set to true. Otherwise the flag is false. Note that the persistState event is provided merely for user convenience, you can achieve the same effect using setInterval() and listening for the migrating event.


  • EventManager
    • PlatformEventManager






config: Configuration = ...



  • close(): Promise<void>
  • 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 of Actor.main().

    Returns Promise<void>


  • emit(event: EventTypeName, ...args: unknown[]): void
  • Parameters

    • externalevent: EventTypeName
    • externalrest...args: unknown[]

    Returns void


  • init(): Promise<void>
  • Initializes event emitter by creating a connection to a websocket that provides them. This is an internal function that is automatically called by Actor.main().

    Returns Promise<void>


  • isInitialized(): boolean
  • Returns boolean


  • off(event: EventTypeName, listener?: (...args: any[]) => any): void
  • Parameters

    • externalevent: EventTypeName
    • externaloptionallistener: (...args: any[]) => any

    Returns void


  • on(event: EventTypeName, listener: (...args: any[]) => any): void
  • Parameters

    • externalevent: EventTypeName
    • externallistener: (...args: any[]) => any

    Returns void