Actor Task Copier
Try for free
No credit card required
View all Actors
Actor Task Copier
mtrunkat/actor-task-copier
Try for free
No credit card required
Copies actor tasks between accounts from one actor to another.
src/main.js
1import { Actor } from 'apify';
2import { ApifyClient } from 'apify-client';
3
4await Actor.init()
5
6const {
7 isDryRun,
8 sourceActorId,
9 sourceApiToken,
10 targetActorId,
11 targetApiToken,
12} = await Actor.getInput();
13
14if (isDryRun) console.log('This is a dry run!');
15
16console.log(sourceApiToken);
17
18const sourceClient = new ApifyClient({ token: sourceApiToken });
19const targetClient = new ApifyClient({ token: targetApiToken });
20
21const sourceActor = await sourceClient.actor(sourceActorId).get();
22const sourceUser = await sourceClient.user().get();
23const targetActor = await targetClient.actor(targetActorId).get();
24const targetUser = await targetClient.user().get();
25
26console.log(`Copying from ${sourceUser.username}/${sourceActor.name} to ${targetUser.username}/${targetActor.name}`);
27
28const tasksToBeCopied = [];
29
30let hasMore = true;
31let offset = 0;
32while (hasMore) {
33 const response = await sourceClient.tasks().list({ limit: 100, offset });
34
35 for (const task of response.items) {
36 if (task.actId === sourceActorId) tasksToBeCopied.push(task);
37 }
38
39 hasMore = response.items.length > 0;
40 offset += response.limit;
41}
42
43console.log('Tasks to be copied:')
44console.log(tasksToBeCopied.map(task => `- ${sourceUser.username}/${task.name}`).join('\n'));
45
46if (!isDryRun) {
47 console.log('Copying tasks...');
48 for (const { id: taskId } of tasksToBeCopied) {
49 const task = await sourceClient.task(taskId).get();
50 await targetClient.tasks().create({
51 actId: targetActorId,
52 name: task.name,
53 options: task.options,
54 input: task.input,
55 });
56 console.log(`${sourceUser.username}/${task.name} copied.`);
57 }
58}
59
60console.log('Done.');
61await Actor.exit();
.dockerignore
1# configurations
2.idea
3
4# crawlee and apify storage folders
5apify_storage
6crawlee_storage
7storage
8
9# installed files
10node_modules
11
12# git folder
13.git
Dockerfile
1# Specify the base Docker image. You can read more about
2# the available images at https://sdk.apify.com/docs/guides/docker-images
3# You can also use any other image from Docker Hub.
4FROM apify/actor-node:16
5
6# Copy just package.json and package-lock.json
7# to speed up the build using Docker layer cache.
8COPY package*.json ./
9
10# Install NPM packages, skip optional and development dependencies to
11# keep the image small. Avoid logging too much and print the dependency
12# tree for debugging
13RUN npm --quiet set progress=false \
14 && npm install --omit=dev --omit=optional \
15 && echo "Installed NPM packages:" \
16 && (npm list --omit=dev --all || true) \
17 && echo "Node.js version:" \
18 && node --version \
19 && echo "NPM version:" \
20 && npm --version \
21 && rm -r ~/.npm
22
23# Next, copy the remaining files and directories with the source code.
24# Since we do this after NPM install, quick build will be really fast
25# for most source file changes.
26COPY . ./
27
28
29# Run the image.
30CMD npm start --silent
INPUT_SCHEMA.json
1{
2 "title": "Add two integers",
3 "type": "object",
4 "schemaVersion": 1,
5 "description": "This actor will copy all the tasks of a source actor and source user under the target actor and target user.",
6 "properties": {
7 "sourceActorId": {
8 "title": "Source Actor ID",
9 "type": "string",
10 "description": "ID of a source actor",
11 "editor": "textfield"
12 },
13 "sourceApiToken": {
14 "title": "Source user API token",
15 "type": "string",
16 "description": "API token of a source user",
17 "editor": "textfield",
18 "isSecret": true
19 },
20 "targetActorId": {
21 "title": "Target Actor ID",
22 "type": "string",
23 "description": "ID of a target actor",
24 "editor": "textfield"
25 },
26 "targetApiToken": {
27 "title": "Target user API token",
28 "type": "string",
29 "description": "API token of a target user",
30 "editor": "textfield",
31 "isSecret": true
32 },
33 "isDryRun": {
34 "title": "Dry run",
35 "type": "boolean",
36 "description": "If dry run is enabled then actor will only list the tasks to be copied."
37 }
38 },
39 "required": ["sourceActorId", "sourceApiToken", "targetActorId", "targetApiToken"]
40}
package.json
1{
2 "name": "getting-started-node",
3 "version": "0.0.1",
4 "type": "module",
5 "description": "This is an example of an Apify actor.",
6 "dependencies": {
7 "apify": "^3.1.0"
8 },
9 "devDependencies": {},
10 "scripts": {
11 "start": "node src/main.js",
12 "test": "echo \"Error: oops, the actor has no tests yet, sad!\" && exit 1"
13 },
14 "author": "It's not you it's me",
15 "license": "ISC"
16}
Developer
Maintained by Community
Actor Metrics
1 monthly user
-
1 star
Created in Oct 2022
Modified 2 years ago
Categories