Skip to content

Latest commit

 

History

History
55 lines (36 loc) · 3.45 KB

File metadata and controls

55 lines (36 loc) · 3.45 KB
id interacting-with-other-actors
title Interacting with other Actors
description Start, call, and metamorph other Actors from within your Actor code.

import RunnableCodeBlock from '@site/src/components/RunnableCodeBlock';

import InteractingStartExample from '!!raw-loader!roa-loader!./code/06_interacting_start.py'; import InteractingCallExample from '!!raw-loader!roa-loader!./code/06_interacting_call.py'; import InteractingCallTaskExample from '!!raw-loader!roa-loader!./code/06_interacting_call_task.py'; import InteractingMetamorphExample from '!!raw-loader!roa-loader!./code/06_interacting_metamorph.py'; import ApiLink from '@site/src/components/ApiLink';

The Apify SDK lets you start, call, and transform (metamorph) other Actors directly from your Actor code. This is useful for composing complex workflows from smaller, reusable Actors.

Actor start

The Actor.start method starts another Actor on the Apify platform, and immediately returns the details of the started Actor run.

{InteractingStartExample}

Actor call

The Actor.call method starts another Actor on the Apify platform, and waits for the started Actor run to finish.

{InteractingCallExample}

Actor call task

The Actor.call_task method starts an Actor task on the Apify platform, and waits for the started Actor run to finish.

{InteractingCallTaskExample}

Actor metamorph

The Actor.metamorph operation transforms an Actor run into a run of another Actor with a new input. This feature is useful if you want to use another Actor to finish the work of your current Actor, instead of internally starting a new Actor run and waiting for its finish. With metamorph, you can easily create new Actors on top of existing ones, and give your users nicer input structure and user interface for the final Actor. For the users of your Actors, the metamorph operation is completely transparent; they will just see your Actor got the work done.

Internally, the system stops the container corresponding to the original Actor run and starts a new container using a different container image. All the default storages are preserved, and the new Actor input is stored under the INPUT-METAMORPH-1 key in the same default key-value store.

To make your Actor compatible with the metamorph operation, use Actor.get_input instead of Actor.get_value('INPUT') to read your Actor input. This method will fetch the input using the right key in a case of metamorphed run.

For example, imagine you have an Actor that accepts a hotel URL on input, and then internally uses the apify/web-scraper public Actor to scrape all the hotel reviews. The metamorphing code would look as follows:

{InteractingMetamorphExample}

For the full list of methods for interacting with other Actors, see the Actor API reference.