Skip to content

Commit 4188aa1

Browse files
committed
Update refresh.py
1 parent 8089eb7 commit 4188aa1

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

samples/refresh.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def main():
2727
# Options specific to this sample
2828
parser.add_argument("resource_type", choices=["workbook", "datasource"])
2929
parser.add_argument("resource_id")
30-
parser.add_argument("--incremental", default=False)
30+
parser.add_argument("--incremental")
31+
parser.add_argument("--synchronous")
3132

3233
args = parser.parse_args()
3334

@@ -43,26 +44,35 @@ def main():
4344

4445

4546
tableau_auth = TSC.PersonalAccessTokenAuth(args.token_name, args.token_value, site_id=args.site)
46-
server = TSC.Server(args.server, use_server_version=True)
47+
server = TSC.Server(args.server, use_server_version=True, http_options={'verify': False})
4748
with server.auth.sign_in(tableau_auth):
4849
if args.resource_type == "workbook":
4950
# Get the workbook by its Id to make sure it exists
5051
resource = server.workbooks.get_by_id(args.resource_id)
52+
print(resource)
5153

5254
# trigger the refresh, you'll get a job id back which can be used to poll for when the refresh is done
5355
job = server.workbooks.refresh(args.resource_id, incremental=incremental)
5456
else:
5557
# Get the datasource by its Id to make sure it exists
5658
resource = server.datasources.get_by_id(args.resource_id)
59+
print(resource)
60+
61+
# server.datasources.create_extract(resource)
5762

5863
# trigger the refresh, you'll get a job id back which can be used to poll for when the refresh is done
59-
job = server.datasources.refresh(resource)
64+
job = server.datasources.refresh(resource, incremental=incremental) # by default runs as a sync task,
6065

61-
print(f"Update job posted (ID: {job.id})")
62-
print("Waiting for job...")
63-
# `wait_for_job` will throw if the job isn't executed successfully
64-
job = server.jobs.wait_for_job(job)
65-
print("Job finished succesfully")
66+
print(f"{refresh_type} job posted (ID: {job.id})")
67+
if args.synchronous:
68+
# equivalent to tabcmd --synchnronous: wait for the job to complete
69+
try:
70+
# `wait_for_job` will throw if the job isn't executed successfully
71+
print("Waiting for job...")
72+
server.jobs.wait_for_job(job)
73+
print("Job finished succesfully")
74+
except Exception as e:
75+
print(f"Job failed! {e}")
6676

6777

6878
if __name__ == "__main__":

0 commit comments

Comments
 (0)