-
Notifications
You must be signed in to change notification settings - Fork 62
docs: add status message section to Actor lifecycle page #586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 <ApiLink to="apify/class/Dataset">`Dataset`</ApiLink> 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 <ApiLink to="class/Actor#setStatusMessage">`Actor.setStatusMessage()`</ApiLink> to set the message: | ||
|
|
||
| <CodeBlock language="js">{StatusMessageSource}</CodeBlock> | ||
|
|
||
| The SDK only sends an API request when the message text changes, so repeating the same message incurs no additional cost. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I don't think this is true. We need to send the request every time, as somebody else might have updated the message in the meantime.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this valid also for Python SDK? I based my prose on Python SDK section about Status Messages so it might also be wrong for Python SDK?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You're right, in Python SDK, the PR fixing it -> apify/apify-sdk-python#859 |
||
|
|
||
| ## Environment variables | ||
|
|
||
| The following are some additional environment variables specific to Apify platform. More Crawlee specific environment variables could be found in the <CrawleeLink to="docs/guides/configuration#environment-variables">Environment Variables</CrawleeLink> guide. | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: the example code is showing exactly this :)