@@ -27,34 +27,51 @@ 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" )
31+ parser .add_argument ("--synchronous" )
3032
3133 args = parser .parse_args ()
3234
3335 # Set logging level based on user input, or error by default
3436 logging_level = getattr (logging , args .logging_level .upper ())
3537 logging .basicConfig (level = logging_level )
3638
39+ refresh_type = "FullRefresh"
40+ incremental = False
41+ if args .incremental :
42+ refresh_type = "Incremental"
43+ incremental = True
44+
3745 tableau_auth = TSC .PersonalAccessTokenAuth (args .token_name , args .token_value , site_id = args .site )
38- server = TSC .Server (args .server , use_server_version = True )
46+ server = TSC .Server (args .server , use_server_version = True , http_options = { "verify" : False } )
3947 with server .auth .sign_in (tableau_auth ):
4048 if args .resource_type == "workbook" :
4149 # Get the workbook by its Id to make sure it exists
4250 resource = server .workbooks .get_by_id (args .resource_id )
51+ print (resource )
4352
4453 # trigger the refresh, you'll get a job id back which can be used to poll for when the refresh is done
45- job = server .workbooks .refresh (args .resource_id )
54+ job = server .workbooks .refresh (args .resource_id , incremental = incremental )
4655 else :
4756 # Get the datasource by its Id to make sure it exists
4857 resource = server .datasources .get_by_id (args .resource_id )
58+ print (resource )
59+
60+ # server.datasources.create_extract(resource)
4961
5062 # trigger the refresh, you'll get a job id back which can be used to poll for when the refresh is done
51- job = server .datasources .refresh (resource )
63+ job = server .datasources .refresh (resource , incremental = incremental ) # by default runs as a sync task,
5264
53- print (f"Update job posted (ID: { job .id } )" )
54- print ("Waiting for job..." )
55- # `wait_for_job` will throw if the job isn't executed successfully
56- job = server .jobs .wait_for_job (job )
57- print ("Job finished succesfully" )
65+ print (f"{ refresh_type } job posted (ID: { job .id } )" )
66+ if args .synchronous :
67+ # equivalent to tabcmd --synchnronous: wait for the job to complete
68+ try :
69+ # `wait_for_job` will throw if the job isn't executed successfully
70+ print ("Waiting for job..." )
71+ server .jobs .wait_for_job (job )
72+ print ("Job finished succesfully" )
73+ except Exception as e :
74+ print (f"Job failed! { e } " )
5875
5976
6077if __name__ == "__main__" :
0 commit comments