Skip to content

Commit df25bf6

Browse files
TC-MOfnesveda
andauthored
docs: improve metamorph section (#1123)
rework logical flow & structure added admonitions --------- Co-authored-by: František Nesveda <[email protected]>
1 parent 430fc0a commit df25bf6

File tree

1 file changed

+41
-5
lines changed
  • sources/platform/actors/development/programming_interface

1 file changed

+41
-5
lines changed

sources/platform/actors/development/programming_interface/metamorph.md

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,51 @@ import TabItem from '@theme/TabItem';
1212

1313
---
1414

15-
This feature is useful if you want to use another Actor to finish the work of your current one instead of internally starting a new Actor run and waiting for it to finish. With metamorph, you can easily create new Actors on top of existing ones, and give your users a nicer input structure and user interface for the final Actor. The metamorph operation is completely transparent to the Actor's users; they will just see that your Actor got the work done.
15+
## Transform Actor runs
1616

17-
Internally, the system stops the Docker container corresponding to the Actor run and starts a new container using a different Docker image. All the default storages are preserved, and the new input is stored under the **INPUT-METAMORPH-1** key in the same default key-value store.
17+
Metamorph is a powerful operation that transforms an Actor run into the run of another Actor with a new input. This feature enables you to leverage existing Actors and create more efficient workflows.
1818

19-
You are limited in how many times you can metamorph a single run. Check the limit in [the Actor runtime limits](/platform/limits#actor-limits).
19+
## Understand metamorph
2020

21-
To make your Actor compatible with the metamorph operation, use `Actor.getInput()` instead of `Actor.getValue('INPUT')`. This method will fetch the input using the right key **INPUT-METAMORPH-1** in case of a metamorphed run.
21+
The metamorph process involves several key steps. It stops the current Actor's Docker container, then starts a new container using a different Docker image. During this transition, all default storages are preserved. The new input is stored under the _INPUT-METAMORPH-1_ key in the default key-value store, ensuring seamless data transfer between Actor runs.
22+
23+
## Benefits of metamorph
24+
25+
Metamorph offers several benefits for developers:
26+
27+
- Seamless transition between Actors without starting a new run
28+
- Building new Actors on top of existing ones
29+
- Providing users with an improved input structure and interface
30+
- Maintaining transparency for end-users
31+
32+
These benefits make metamorph a valuable tool for creating complex, efficient workflows.
33+
34+
## Implementation guidelines
35+
36+
To make your Actor compatible with metamorph, use `Actor.getInput()` instead of `Actor.getValue(&#96;INPUT&#96;)`. This method fetches the input using the correct key (_INPUT-METAMORPH-1_) for metamorphed runs, ensuring proper data retrieval in transformed Actor runs.
37+
38+
:::note Runtime limits
39+
40+
There's a limit to how many times you can metamorph a single run. Refer to the [Actor runtime limits](/platform/limits#actor-limits) for more details.
41+
42+
:::
43+
44+
## Example
45+
46+
Let's walk through an example of using metamorph to create a hotel review scraper:
47+
48+
1. Create an Actor that accepts a hotel URL as input.
49+
50+
1. Use the [apify/web-scraper](https://www.apify.com/apify/web-scraper) Actor to scrape reviews.
51+
52+
1. Use the metamorph operation to transform into a run of apify/web-scraper.
2253

23-
For example, imagine you have an Actor that accepts a hotel URL on input and then internally uses the [apify/web-scraper](https://www.apify.com/apify/web-scraper) Actor to scrape all the hotel reviews. The metamorphing code would look like this:
2454

2555
<Tabs groupId="main">
2656
<TabItem value="JavaScript" label="JavaScript">
2757

58+
Here's the JavaScript code to achieve this:
59+
2860
```js
2961
import { Actor } from 'apify';
3062

@@ -56,6 +88,8 @@ await Actor.exit();
5688
</TabItem>
5789
<TabItem value="Python" label="Python">
5890

91+
Here's the Python code to achieve this:
92+
5993
```python
6094
from apify import Actor
6195

@@ -83,3 +117,5 @@ async def main():
83117

84118
</TabItem>
85119
</Tabs>
120+
121+
By following these steps, you can create a powerful hotel review scraper that leverages the capabilities of existing Actors through the metamorph operation.

0 commit comments

Comments
 (0)