Skip to content

Commit 47ca815

Browse files
authored
docs: Update a part of docs for 2.0 (#245)
- **Remove mention of Actor.main** - **Update example** - **Update example**
1 parent dec675a commit 47ca815

File tree

3 files changed

+7
-25
lines changed

3 files changed

+7
-25
lines changed

docs/03-concepts/01-actor-lifecycle.mdx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,23 +57,6 @@ async def main():
5757
raise RuntimeError('Ouch!')
5858
```
5959

60-
#### Main function
61-
62-
Another option is to pass a function to the Actor via the [`Actor.main(main_func)`](../../reference/class/Actor#main) method,
63-
which causes the Actor to initialize, run the main function, and exit, catching any runtime errors in the passed function.
64-
65-
```python title="src/main.py"
66-
from apify import Actor
67-
68-
async def actor_main_func():
69-
Actor.log.info('Actor input:', await Actor.get_input())
70-
await Actor.set_value('OUTPUT', 'Hello, world!')
71-
raise RuntimeError('Ouch!')
72-
73-
async def main():
74-
await Actor.main(actor_main_func)
75-
```
76-
7760
### Rebooting an Actor
7861

7962
Sometimes, you want to restart your Actor to make it run from the beginning again.

docs/03-concepts/04-actor-events.mdx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,7 @@ and to remove them, you use the [`Actor.off()`](../../reference/class/Actor#off)
7575

7676
```python title="src/main.py"
7777
import asyncio
78-
from apify import Actor
79-
from apify_shared.consts import ActorEventTypes
78+
from apify import Actor, Event
8079

8180
async def main():
8281
async with Actor:
@@ -94,7 +93,7 @@ async def main():
9493
Actor.log.info('Saving Actor state', extra=event_data)
9594
await Actor.set_value('STATE', processed_items)
9695

97-
Actor.on(ActorEventTypes.PERSIST_STATE, save_state)
96+
Actor.on(Event.PERSIST_STATE, save_state)
9897

9998
# Do some fake work
10099
for i in range(processed_items, total_items):
@@ -103,7 +102,7 @@ async def main():
103102
await asyncio.sleep(0.1)
104103

105104
# Suppose we can stop saving the state now
106-
Actor.off(ActorEventTypes.PERSIST_STATE, save_state)
105+
Actor.off(Event.PERSIST_STATE, save_state)
107106

108107
# Do some more fake work, this time something that can't be restarted,
109108
# so no point persisting the state

docs/03-concepts/11-configuration.mdx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,19 @@ or the list of environment variables that the Actor understands.
2121
This will cause the Actor to persist its state every 10 seconds:
2222

2323
```python title="src/main.py"
24-
from apify import Actor
25-
from apify_shared.consts import ActorEventTypes
24+
from datetime import timedelta
25+
from apify import Actor, Event, Configuration
2626

2727
async def main():
2828
global_config = Configuration.get_global_configuration()
29-
global_config.persist_state_interval_millis = 10000
29+
global_config.persist_state_interval = timedelta(seconds=10)
3030

3131
async with Actor:
3232
async def save_state():
3333
await Actor.set_value('STATE', 'Hello, world!')
3434

3535
# The `save_state` handler will be called every 10 seconds now
36-
Actor.on(ActorEventTypes.PERSIST_STATE, save_state)
36+
Actor.on(Event.PERSIST_STATE, save_state)
3737
```
3838

3939
### Configuring via environment variables

0 commit comments

Comments
 (0)