You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sources/platform/actors/development/programming_interface/metamorph.md
+41-5Lines changed: 41 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,19 +12,51 @@ import TabItem from '@theme/TabItem';
12
12
13
13
---
14
14
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
16
16
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.
18
18
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
20
20
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(`INPUT`)`. 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.
22
53
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:
24
54
25
55
<TabsgroupId="main">
26
56
<TabItemvalue="JavaScript"label="JavaScript">
27
57
58
+
Here's the JavaScript code to achieve this:
59
+
28
60
```js
29
61
import { Actor } from'apify';
30
62
@@ -56,6 +88,8 @@ await Actor.exit();
56
88
</TabItem>
57
89
<TabItemvalue="Python"label="Python">
58
90
91
+
Here's the Python code to achieve this:
92
+
59
93
```python
60
94
from apify import Actor
61
95
@@ -83,3 +117,5 @@ async def main():
83
117
84
118
</TabItem>
85
119
</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