Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions docs/02_concepts/01_actor_lifecycle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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_),
Expand Down Expand Up @@ -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.
Copy link
Copy Markdown
Member

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 :)


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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SDK only sends an API request when the message text changes

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe so, the code doesn't seem to indicate anything like this.

I see this was added to the Python SDK docs by @vdusek - do you have any idea what this was referring to, Vlada?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, in Python SDK, the set_status_message() calls self.apify_client.run(...).update(status_message=...) every time and the sentence "The SDK only sends an API request when the message text changes" is wrong.

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.
Expand Down
30 changes: 30 additions & 0 deletions docs/02_concepts/code/status_message.ts
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();