Skip to content

Commit f91369a

Browse files
docs: Add synthetic start event
1 parent 56bf9c2 commit f91369a

File tree

2 files changed

+19
-54
lines changed

2 files changed

+19
-54
lines changed
152 KB
Loading

sources/platform/actors/publishing/monetize/pay_per_event.mdx

Lines changed: 19 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ PPE lets you define pricing for individual events. You can charge for specific e
1818

1919
The details on how your cost is computed can be found in [Example of a PPE pricing model](#example-of-a-ppe-pricing-model).
2020

21+
:::tip Additional benefits
22+
23+
Actors that implement PPE pricing receive additional benefits, including increased visibility in Apify Store and enhanced discoverability for users looking for monetized solutions.
24+
25+
:::
26+
2127
## How is profit computed
2228

2329
Your profit is calculated from the mentioned formula:
@@ -77,71 +83,30 @@ When using browser automation tools like Puppeteer or Playwright for web scrapin
7783

7884
:::
7985

80-
### Charge for `Actor start`
81-
82-
Charge for `Actor start` to prevent users from running your Actor for free.
83-
84-
<Tabs groupId="main">
85-
<TabItem value="JavaScript" label="JavaScript">
86-
87-
```js
88-
import { Actor } from 'apify';
89-
90-
const chargeForActorStart = async () => {
91-
const chargingManager = Actor.getChargingManager();
86+
### Use synthetic start event `apify-actor-start`
9287

93-
// Don't charge the "Actor start" event again after Actor migration
94-
if (chargingManager.getChargedEventCount("actor-start") === 0) {
95-
await Actor.charge({
96-
"eventName": "actor-start",
97-
});
98-
}
99-
}
88+
This event is automatically charged by the Apify platform when an Actor is started or resurrected.
10089

101-
await Actor.init();
90+
You are charged one event for each GB of memory used by the Actor (at least one event per run). This also saves you the cost of 5 seconds of Actor runtime.
10291

103-
const main = async () => {
104-
await chargeForActorStart();
92+
:::note Automatic charging of synthetic start event
10593

106-
// Rest of the Actor logic
107-
};
94+
You do **not** need to manually charge for the synthetic start event (`apify-actor-start`) in your Actor code.
10895

109-
await main();
96+
If you attempt to charge this event yourself, the operation will fail.
97+
This event is **always** charged automatically by the Apify platform whenever your Actor starts or is resurrected.
11098

111-
await Actor.exit();
112-
```
113-
114-
</TabItem>
115-
<TabItem value="Python" label="Python">
116-
117-
```py
118-
from apify import Actor
119-
120-
async def charge_for_actor_start():
121-
charging_manager = Actor.get_charging_manager()
122-
123-
# Don't charge the "Actor start" event again after Actor migration
124-
if charging_manager.get_charged_event_count("actor-start") == 0:
125-
await Actor.charge(event_name="actor-start")
126-
127-
async def main():
128-
await Actor.init()
129-
130-
await charge_for_actor_start()
131-
132-
# Rest of the Actor logic
99+
:::
133100

134-
await Actor.exit()
135-
```
101+
#### Synthetic start event for new Actors
136102

137-
</TabItem>
138-
</Tabs>
103+
For new Actors, this event is added automatically as you can see on the following screen:
139104

140-
:::note Actor migrations and charging
105+
![New Actor - synthetic start event](../images/apify-actor-start.png)
141106

142-
Actors can migrate between servers during execution, which restarts the process and clears memory. When using PPE pricing model, avoid charging the start event multiple times after a migration by checking your charging state.
107+
#### Synthetic start event for existing Actors
143108

144-
:::
109+
If you have existing Actors, you can add this event manually in the Apify Console.
145110

146111
### Charge for invalid input
147112

0 commit comments

Comments
 (0)