Repository navigation
Expose refreshExtractTriggered on SubscriptionItem #1861
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
Open
jacalata
wants to merge
5
commits into
development
Choose a base branch
from
jac/subscription-refresh-extract-triggered
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5b5c90a
feat: expose refreshExtractTriggered on SubscriptionItem (#1658)
jacalata 4207f7f
Address fresh-eyes review on refreshExtractTriggered subscriptions
jacalata 81cbdc2
Address review: Cloud round-trip + hardening on refreshExtractTriggered
jacalata 1a423a9
Address Copilot round-2 findings on inline schedule parsing
jacalata 055573d
Address Copilot findings: whitespace-only schedule_id and typo
jacalata 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,108 @@ | ||
| #### | ||
| # This script creates a Tableau Cloud "On Extract Refresh" subscription: | ||
| # a subscription that fires when an extract-refresh schedule completes, | ||
| # rather than on the schedule's time trigger. Recipients get the email | ||
| # alongside the refresh, so they always see the freshest data. | ||
| # | ||
| # What it does: | ||
| # 1. Sign in. | ||
| # 2. Look up the target view or workbook by name. | ||
| # 3. List extract-refresh schedules and pick the one you named. | ||
| # 4. Build the subscription via SubscriptionItem.on_extract_refresh(). | ||
| # 5. Call subscriptions.create() and print the new subscription id. | ||
| # | ||
| # On Tableau Server this same script works as long as the schedule you | ||
| # reference is an extract-refresh schedule; the "On Extract Refresh" | ||
| # terminology is Cloud-UI-specific but the REST attribute | ||
| # (refreshExtractTriggered) is the same on both. | ||
| # | ||
| # Requires Python 3.10 or later. | ||
| #### | ||
|
|
||
|
|
||
| import argparse | ||
| import logging | ||
|
|
||
| import tableauserverclient as TSC | ||
|
|
||
|
|
||
| def usage(args): | ||
| parser = argparse.ArgumentParser(description="Create an On Extract Refresh subscription for a view or workbook.") | ||
| # Common options; keep in sync across samples. | ||
| parser.add_argument("--server", "-s", required=True, help="server address") | ||
| parser.add_argument("--site", "-S", default="", help="site content URL") | ||
| parser.add_argument("--token-name", "-p", required=True, help="personal access token name") | ||
| parser.add_argument("--token-value", "-v", required=True, help="personal access token value") | ||
| parser.add_argument( | ||
| "--logging-level", | ||
| "-l", | ||
| choices=["debug", "info", "error"], | ||
| default="error", | ||
| ) | ||
| # Sample-specific options. | ||
| parser.add_argument("--subject", required=True, help="subscription subject line") | ||
| parser.add_argument("--schedule", required=True, help="name of the extract-refresh schedule to attach to") | ||
| parser.add_argument("--user", required=True, help="username of the subscription recipient") | ||
| target = parser.add_mutually_exclusive_group(required=True) | ||
| target.add_argument("--view", help="name of the view to send") | ||
| target.add_argument("--workbook", help="name of the workbook to send") | ||
| return parser.parse_args(args) | ||
|
|
||
|
|
||
| def _find_one(items, label, name): | ||
| matches = [i for i in items if i.name == name] | ||
| if len(matches) != 1: | ||
| raise SystemExit(f"expected exactly one {label} named {name!r}, found {len(matches)}") | ||
| return matches[0] | ||
|
|
||
|
|
||
| def find_extract_refresh_schedule(server, name): | ||
| schedules = [s for s in TSC.Pager(server.schedules) if s.schedule_type == TSC.ScheduleItem.Type.Extract] | ||
| return _find_one(schedules, "extract-refresh schedule", name) | ||
|
|
||
|
|
||
| def find_view(server, name): | ||
| return _find_one(list(TSC.Pager(server.views)), "view", name) | ||
|
|
||
|
|
||
| def find_workbook(server, name): | ||
| return _find_one(list(TSC.Pager(server.workbooks)), "workbook", name) | ||
|
|
||
|
|
||
| def find_user(server, name): | ||
| return _find_one(list(TSC.Pager(server.users)), "user", name) | ||
|
|
||
|
|
||
| def run(args): | ||
| logging.basicConfig(level=getattr(logging, args.logging_level.upper())) | ||
|
|
||
| auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site) | ||
| server = TSC.Server(args.server, use_server_version=True) | ||
| with server.auth.sign_in(auth): | ||
| schedule = find_extract_refresh_schedule(server, args.schedule) | ||
| user = find_user(server, args.user) | ||
| if args.view: | ||
| content = find_view(server, args.view) | ||
| target = TSC.Target(content.id, "view") | ||
| else: | ||
| content = find_workbook(server, args.workbook) | ||
| target = TSC.Target(content.id, "workbook") | ||
|
|
||
| subscription = TSC.SubscriptionItem.on_extract_refresh( | ||
| subject=args.subject, | ||
| extract_refresh_schedule_id=schedule.id, | ||
| user_id=user.id, | ||
| target=target, | ||
| ) | ||
| created = server.subscriptions.create(subscription) | ||
| print(f"Created subscription {created.id}: {created.subject!r} on schedule {schedule.name!r}") | ||
|
|
||
|
|
||
| def main(): | ||
| import sys | ||
|
|
||
| run(usage(sys.argv[1:])) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.