diff --git a/docs/02_concepts/01_actor_lifecycle.mdx b/docs/02_concepts/01_actor_lifecycle.mdx index 9d1511607d..2e556b539d 100644 --- a/docs/02_concepts/01_actor_lifecycle.mdx +++ b/docs/02_concepts/01_actor_lifecycle.mdx @@ -13,6 +13,7 @@ import CodeBlock from '@theme/CodeBlock'; import MainSource from '!!raw-loader!./apify_platform_main.ts'; import InitExitSource from '!!raw-loader!./apify_platform_init_exit.ts'; +import StatusMessageSource from '!!raw-loader!./code/status_message.ts'; [Apify](https://apify.com) is a platform built to serve large-scale and high-performance web scraping and automation needs. It provides easy access to compute instances (_Actors_), @@ -198,6 +199,18 @@ When the `Dataset` is stored on the - [Datasets API reference](https://docs.apify.com/api/v2#/reference/datasets) - [Request queues API reference](https://docs.apify.com/api/v2#/reference/request-queues) +## Status messages + +[Status messages](https://docs.apify.com//platform/actors/development/programming-interface/status-messages) are lightweight, human-readable progress indicators displayed with the Actor run in the Apify Console (separate from logs). Use them to communicate high-level phases or milestones, such as "Fetching list", "Processed 120/500 pages", or "Uploading results". + +Update the status only when the user's understanding of progress changes - avoid frequent updates for every processed item. Detailed information should go to logs or storages (Dataset, Key-value store) instead. + +Use `Actor.setStatusMessage()` to set the message: + +{StatusMessageSource} + +The SDK only sends an API request when the message text changes, so repeating the same message incurs no additional cost. + ## Environment variables The following are some additional environment variables specific to Apify platform. More Crawlee specific environment variables could be found in the Environment Variables guide. diff --git a/docs/02_concepts/code/status_message.ts b/docs/02_concepts/code/status_message.ts new file mode 100644 index 0000000000..2be618b08e --- /dev/null +++ b/docs/02_concepts/code/status_message.ts @@ -0,0 +1,30 @@ +import { Actor } from 'apify'; + +await Actor.init(); + +// highlight-start +await Actor.setStatusMessage('Fetching the list of URLs...'); +// highlight-end + +// Simulate some work +const urls = [ + 'https://example.com/1', + 'https://example.com/2', + 'https://example.com/3', +]; + +for (let i = 0; i < urls.length; i++) { + // Process each URL... + // highlight-start + await Actor.setStatusMessage(`Processing ${i + 1} of ${urls.length} URLs`); + // highlight-end +} + +// highlight-start +// Mark the final status message as terminal +await Actor.setStatusMessage('All URLs processed successfully!', { + isStatusMessageTerminal: true, +}); +// highlight-end + +await Actor.exit();