-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Apify - Get Dataset Items, Run Task Synchronously #16212
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
components/apify/actions/get-dataset-items/get-dataset-items.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import apify from "../../apify.app.mjs"; | ||
| import { LIMIT } from "../../common/constants.mjs"; | ||
|
|
||
| export default { | ||
| key: "apify-get-dataset-items", | ||
| name: "Get Dataset Items", | ||
| description: "Returns data stored in a dataset. [See the documentation](https://docs.apify.com/api/v2/dataset-items-get)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| apify, | ||
| datasetId: { | ||
| propDefinition: [ | ||
| apify, | ||
| "datasetId", | ||
| ], | ||
| }, | ||
| clean: { | ||
| propDefinition: [ | ||
| apify, | ||
| "clean", | ||
| ], | ||
| }, | ||
| fields: { | ||
| propDefinition: [ | ||
| apify, | ||
| "fields", | ||
| ], | ||
| }, | ||
| omit: { | ||
| propDefinition: [ | ||
| apify, | ||
| "omit", | ||
| ], | ||
| }, | ||
| flatten: { | ||
| propDefinition: [ | ||
| apify, | ||
| "flatten", | ||
| ], | ||
| }, | ||
| maxResults: { | ||
| propDefinition: [ | ||
| apify, | ||
| "maxResults", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const params = { | ||
| limit: LIMIT, | ||
| offset: 0, | ||
| clean: this.clean, | ||
| fields: this.fields && this.fields.join(), | ||
| omit: this.omit && this.omit.join(), | ||
| flatten: this.flatten && this.flatten.join(), | ||
| }; | ||
|
|
||
| const results = []; | ||
| let total; | ||
|
|
||
| do { | ||
| const items = await this.apify.listDatasetItems({ | ||
| $, | ||
| datasetId: this.datasetId, | ||
| params, | ||
| }); | ||
| results.push(...items); | ||
| if (results.length >= this.maxResults) { | ||
| break; | ||
| } | ||
| total = items?.length; | ||
| params.offset += LIMIT; | ||
| } while (total); | ||
|
|
||
| if (results.length > this.maxResults) { | ||
| results.length = this.maxResults; | ||
| } | ||
|
|
||
| if (results.length > 0) { | ||
| $.export("$summary", `Successfully retrieved ${results.length} item${results.length === 1 | ||
| ? "" | ||
| : "s"}`); | ||
| } | ||
| return results; | ||
| }, | ||
| }; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
components/apify/actions/run-task-synchronously/run-task-synchronously.mjs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| import apify from "../../apify.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "apify-run-task-synchronously", | ||
| name: "Run Task Synchronously", | ||
| description: "Run a specific task and return its dataset items. [See the documentation](https://docs.apify.com/api/v2/actor-task-run-sync-get-dataset-items-get)", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| apify, | ||
| taskId: { | ||
| propDefinition: [ | ||
| apify, | ||
| "taskId", | ||
| ], | ||
| description: "The ID of the task to run", | ||
| }, | ||
| timeout: { | ||
| type: "integer", | ||
| label: "Timeout", | ||
| description: "Optional timeout for the run, in seconds. By default, the run uses a timeout specified in the task settings.", | ||
| optional: true, | ||
| }, | ||
| memory: { | ||
| type: "integer", | ||
| label: "Memory", | ||
| description: "Memory limit for the run, in megabytes. The amount of memory can be set to a power of 2 with a minimum of 128. By default, the run uses a memory limit specified in the task settings.", | ||
| optional: true, | ||
| }, | ||
| build: { | ||
| type: "string", | ||
| label: "Build", | ||
| description: "Specifies the Actor build to run. It can be either a build tag or build number. By default, the run uses the build specified in the task settings (typically latest).", | ||
| optional: true, | ||
| }, | ||
| clean: { | ||
| propDefinition: [ | ||
| apify, | ||
| "clean", | ||
| ], | ||
| }, | ||
| fields: { | ||
| propDefinition: [ | ||
| apify, | ||
| "fields", | ||
| ], | ||
| }, | ||
| omit: { | ||
| propDefinition: [ | ||
| apify, | ||
| "omit", | ||
| ], | ||
| }, | ||
| flatten: { | ||
| propDefinition: [ | ||
| apify, | ||
| "flatten", | ||
| ], | ||
| }, | ||
| maxResults: { | ||
| propDefinition: [ | ||
| apify, | ||
| "maxResults", | ||
| ], | ||
| }, | ||
| }, | ||
| async run({ $ }) { | ||
| const response = await this.apify.runTaskSynchronously({ | ||
| $, | ||
| taskId: this.taskId, | ||
| params: { | ||
| timeout: this.timeout, | ||
| memory: this.memory, | ||
| build: this.build, | ||
| clean: this.clean, | ||
| fields: this.fields && this.fields.join(), | ||
| omit: this.omit && this.omit.join(), | ||
| flatten: this.flatten && this.flatten.join(), | ||
| maxItems: this.maxResults, | ||
| }, | ||
| }); | ||
|
|
||
| $.export("$summary", `Successfully ran task with ID: ${this.taskId}`); | ||
|
|
||
| return response; | ||
| }, | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.