-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add TTL functionality to Data Store actions #15824
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 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1316268
Add TTL functionality to Data Store actions
dannyroosevelt cc8c838
Update pnpm-lock.yaml
dannyroosevelt d7325b0
Update TTL max limit to 1 year and increment versions of all data sto…
dannyroosevelt e12f1a5
Update components/data_stores/actions/update-ttl/update-ttl.mjs
dannyroosevelt 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
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
121 changes: 121 additions & 0 deletions
121
components/data_stores/actions/update-ttl/update-ttl.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,121 @@ | ||
| import app from "../../data_stores.app.mjs"; | ||
|
|
||
| export default { | ||
| key: "data_stores-update-ttl", | ||
| name: "Update record expiration", | ||
| description: "Update the expiration time for a record in your [Pipedream Data Store](https://pipedream.com/data-stores/).", | ||
| version: "0.0.1", | ||
| type: "action", | ||
| props: { | ||
| app, | ||
| dataStore: { | ||
| propDefinition: [ | ||
| app, | ||
| "dataStore", | ||
| ], | ||
| }, | ||
| key: { | ||
| propDefinition: [ | ||
| app, | ||
| "key", | ||
| ({ dataStore }) => ({ | ||
| dataStore, | ||
| }), | ||
| ], | ||
| description: "Select the key for the record you'd like to update the expiration time.", | ||
| }, | ||
| ttlOption: { | ||
| type: "string", | ||
| label: "Expiration Type", | ||
| description: "Choose a common expiration time or specify a custom value", | ||
| options: [ | ||
| { | ||
| label: "Custom value", | ||
| value: "custom", | ||
| }, | ||
| { | ||
| label: "No expiration (remove expiry)", | ||
| value: "0", | ||
| }, | ||
| { | ||
| label: "1 hour", | ||
| value: "3600", | ||
| }, | ||
| { | ||
| label: "1 day", | ||
| value: "86400", | ||
| }, | ||
| { | ||
| label: "1 week", | ||
| value: "604800", | ||
| }, | ||
| { | ||
| label: "30 days", | ||
| value: "2592000", | ||
| }, | ||
| { | ||
| label: "90 days", | ||
| value: "7776000", | ||
| }, | ||
| { | ||
| label: "1 year", | ||
| value: "31536000", | ||
| }, | ||
| ], | ||
| reloadProps: true, | ||
| }, | ||
| }, | ||
| async additionalProps() { | ||
| const props = {}; | ||
| if (this.ttlOption === "custom") { | ||
| props.ttl = { | ||
| type: "integer", | ||
| label: "Custom TTL (seconds)", | ||
| description: "The number of seconds until this record expires and is automatically deleted. Use 0 to remove expiration.", | ||
| min: 0, | ||
| max: 63072000, // 2 years (safe upper limit) | ||
| }; | ||
| } | ||
| return props; | ||
| }, | ||
| async run({ $ }) { | ||
| const { | ||
| key, ttlOption, ttl, | ||
| } = this; | ||
|
|
||
| // Determine TTL value to use | ||
| const ttlValue = ttlOption === "custom" | ||
| ? ttl | ||
| : parseInt(ttlOption, 10); | ||
|
|
||
| if (!await this.dataStore.has(key)) { | ||
| $.export("$summary", `No record found with key \`${key}\`.`); | ||
| return { | ||
| success: false, | ||
| message: `No record found with key ${key}`, | ||
| }; | ||
| } | ||
|
|
||
| if (ttlValue === 0) { | ||
| // Remove expiration | ||
| await this.dataStore.setTtl(key, null); | ||
| $.export("$summary", `Successfully removed expiration for key \`${key}\`.`); | ||
| return { | ||
| success: true, | ||
| key, | ||
| ttl: null, | ||
| message: "Expiration removed", | ||
| }; | ||
| } else { | ||
| // Update TTL | ||
| await this.dataStore.setTtl(key, ttlValue); | ||
| $.export("$summary", `Successfully updated expiration for key \`${key}\` (expires in ${this.app.formatTtl(ttlValue)}).`); | ||
| return { | ||
| success: true, | ||
| key, | ||
| ttl: ttlValue, | ||
| ttlFormatted: this.app.formatTtl(ttlValue), | ||
| }; | ||
| } | ||
| }, | ||
| }; | ||
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.