Skip to content

Commit e369100

Browse files
patrikbraborecmhamasTC-MO
authored
docs: Add synthetic start event (#1915)
The docs for synthetic start event. Related to the PR: apify/apify-core#22673. --------- Co-authored-by: Matej Hamas <[email protected]> Co-authored-by: Michał Olender <[email protected]>
1 parent cddaa30 commit e369100

File tree

2 files changed

+22
-51
lines changed

2 files changed

+22
-51
lines changed
152 KB
Loading

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

Lines changed: 22 additions & 51 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,36 @@ 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();
92-
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-
}
100-
101-
await Actor.init();
102-
103-
const main = async () => {
104-
await chargeForActorStart();
86+
### Use synthetic start event `apify-actor-start`
10587

106-
// Rest of the Actor logic
107-
};
88+
This event is automatically charged by the Apify platform when an Actor is started or resurrected.
10889

109-
await main();
90+
Users of your Actor are charged one event for each GB of memory used by the Actor (at least one event per run). We _strongly_ suggest setting the price of this event to $0.0001 to remain competitive in the Store and attractive for your customers. If you define this event, you also save 5 seconds of Actor runtime from each Actor run, which won't be deducted from your payout profits.
11091

111-
await Actor.exit();
112-
```
92+
:::note Automatic charging of synthetic start event
11393

114-
</TabItem>
115-
<TabItem value="Python" label="Python">
94+
You must _not_ manually charge for the synthetic start event (`apify-actor-start`) in your Actor code.
11695

117-
```py
118-
from apify import Actor
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.
11998

120-
async def charge_for_actor_start():
121-
charging_manager = Actor.get_charging_manager()
99+
:::
122100

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")
101+
#### Synthetic start event for new Actors
126102

127-
async def main():
128-
await Actor.init()
129-
130-
await charge_for_actor_start()
103+
For new Actors, this event is added automatically as you can see on the following screen:
131104

132-
# Rest of the Actor logic
105+
![New Actor - synthetic start event](../images/apify-actor-start.png)
133106

134-
await Actor.exit()
135-
```
107+
#### Synthetic start event for existing Actors
136108

137-
</TabItem>
138-
</Tabs>
109+
If you have existing Actors, you can add this event manually in Apify Console.
139110

140-
:::note Actor migrations and charging
111+
#### Synthetic start event for Actors with start event
141112

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.
113+
Your Actor might already have a start event defined, such as `actor-start` or another variant of the event name. In this case, you can choose whether to use the synthetic start event or keep the existing start event.
143114

144-
:::
115+
If you want to use the synthetic start event, remove the existing start event from your Actor and add the synthetic start event in Apify Console.
145116

146117
### Charge for invalid input
147118

0 commit comments

Comments
 (0)