diff --git a/docs/03-concepts/01-actor-lifecycle.mdx b/docs/03-concepts/01-actor-lifecycle.mdx index cfbc6154..953040da 100644 --- a/docs/03-concepts/01-actor-lifecycle.mdx +++ b/docs/03-concepts/01-actor-lifecycle.mdx @@ -57,23 +57,6 @@ async def main(): raise RuntimeError('Ouch!') ``` -#### Main function - -Another option is to pass a function to the Actor via the [`Actor.main(main_func)`](../../reference/class/Actor#main) method, -which causes the Actor to initialize, run the main function, and exit, catching any runtime errors in the passed function. - -```python title="src/main.py" -from apify import Actor - -async def actor_main_func(): - Actor.log.info('Actor input:', await Actor.get_input()) - await Actor.set_value('OUTPUT', 'Hello, world!') - raise RuntimeError('Ouch!') - -async def main(): - await Actor.main(actor_main_func) -``` - ### Rebooting an Actor Sometimes, you want to restart your Actor to make it run from the beginning again. diff --git a/docs/03-concepts/04-actor-events.mdx b/docs/03-concepts/04-actor-events.mdx index c041035b..575c37e3 100644 --- a/docs/03-concepts/04-actor-events.mdx +++ b/docs/03-concepts/04-actor-events.mdx @@ -75,8 +75,7 @@ and to remove them, you use the [`Actor.off()`](../../reference/class/Actor#off) ```python title="src/main.py" import asyncio -from apify import Actor -from apify_shared.consts import ActorEventTypes +from apify import Actor, Event async def main(): async with Actor: @@ -94,7 +93,7 @@ async def main(): Actor.log.info('Saving Actor state', extra=event_data) await Actor.set_value('STATE', processed_items) - Actor.on(ActorEventTypes.PERSIST_STATE, save_state) + Actor.on(Event.PERSIST_STATE, save_state) # Do some fake work for i in range(processed_items, total_items): @@ -103,7 +102,7 @@ async def main(): await asyncio.sleep(0.1) # Suppose we can stop saving the state now - Actor.off(ActorEventTypes.PERSIST_STATE, save_state) + Actor.off(Event.PERSIST_STATE, save_state) # Do some more fake work, this time something that can't be restarted, # so no point persisting the state diff --git a/docs/03-concepts/11-configuration.mdx b/docs/03-concepts/11-configuration.mdx index 70b26858..9a4ad329 100644 --- a/docs/03-concepts/11-configuration.mdx +++ b/docs/03-concepts/11-configuration.mdx @@ -21,19 +21,19 @@ or the list of environment variables that the Actor understands. This will cause the Actor to persist its state every 10 seconds: ```python title="src/main.py" -from apify import Actor -from apify_shared.consts import ActorEventTypes +from datetime import timedelta +from apify import Actor, Event, Configuration async def main(): global_config = Configuration.get_global_configuration() - global_config.persist_state_interval_millis = 10000 + global_config.persist_state_interval = timedelta(seconds=10) async with Actor: async def save_state(): await Actor.set_value('STATE', 'Hello, world!') # The `save_state` handler will be called every 10 seconds now - Actor.on(ActorEventTypes.PERSIST_STATE, save_state) + Actor.on(Event.PERSIST_STATE, save_state) ``` ### Configuring via environment variables