The following instructions allows you to extract refresh data sources in the online Tableau server through exMon. This provides better insight of the refreshes and more control over the refresh schedule.


Extract Refresh in exMon

1. Start by saving the following python scripts to the C: drive.


Name of script: Refresh_tableau_online_extract.py

import sys
import argparse


from API_Handler import APIHandler

# ----------------------------------------------------
# ----------------------------------------------------
# ----------------------------------------------------

parser = argparse.ArgumentParser(description='Bakvordur Datapump')
parser.add_argument('--user', required=True, help='Type of .')
parser.add_argument('--pw', required=True, help='Type of .')
parser.add_argument('--url', required=True, help='Type of .')
parser.add_argument('--site', required=True, help='Type of .')
parser.add_argument('--datasource', required=True, help='Type of .')
args = parser.parse_args()

pumpConfig = {}
pumpConfig['user'] = args.user
pumpConfig['pw'] = args.pw
pumpConfig['url'] = args.url
pumpConfig['site'] = args.site
pumpConfig['datasource'] = args.datasource

# ----------------------------------------------------
# ----------------------------------------------------
# ----------------------------------------------------

apiHan = APIHandler(pumpConfig['user'], pumpConfig['pw'], pumpConfig['url'], pumpConfig['site'], pumpConfig['datasource'])

test = apiHan.RunRefresh()

temp = ''


Name of script: API_Handler.py

import requests
import xml.etree.ElementTree as ET 
import time
import datetime

import tableauserverclient as TSC

class APIHandler(object):
    def __init__(self, user, pw, url, site, datasource):
        self.user = user
        self.pw = pw
        self.site = site
        self.url = url 
        self.datasource = datasource

        self.Initialize()

    def Initialize(self):
        tableau_auth = TSC.TableauAuth(self.user, self.pw, site_id=self.site)
        self.server = TSC.Server(self.url, use_server_version=True)
        self.server.auth.sign_in(tableau_auth)

    def RunRefresh(self):
        all_datasources, pagination_item = self.server.datasources.get()

        for dSource in all_datasources:
            if dSource.name == self.datasource:
                try: 
                    datasource = self.server.datasources.get_by_id(dSource.id)
                    refreshed_datasource = self.server.datasources.refresh(datasource)
                    self.HandleRefreshWait(refreshed_datasource.id)
                except Exception as e:
                    print('Refresh failed with error: ' + str(e))
                    exit(1)

    def HandleRefreshWait(self, jobId):
        complete_time = None 
        counter = 0
        started = False
        sleep_timer = 10
        while complete_time is None: 
            extract = self.server.jobs.get_by_id(jobId)

            if str(extract._finish_code) == "0": 
                complete_time = (extract._completed_at).strftime('%Y-%m-%d %H:%M:%S') 
            else:
                if extract.started_at is None: 
                    print("Refresh has not started.") 
                else: 
                    if started == False: 
                        print("Refresh started at " + (extract._started_at).strftime('%Y-%m-%d %H:%M:%S') + '.')
                        started = True
                    if counter == 0:
                        print("Refresh is running.")
                    else:
                        print("Refresh is still running.")

                    counter += 1

            if complete_time is None: 
                time.sleep(sleep_timer) 

        refresh_time = counter*sleep_timer

2. Create a Package for the refresh extract for the data source. It is necessary to create a package for each data source.


3. In the extract refresh package put the following information in the Production - PROD command


  • Identify the Execution Connection
  • Establish the location of the python script in the command window, as well as the highlighted parameters that can be determined in the Tableau online server.
  • NOTE, we highly recommend using Global Parameter to hide the password used in the command window for increased security

_____________________________________________________________________________________________________________________________________

Execution Example

  • site url and site name
The site url and site name are established in the online path of the Tableau online server


------------------------------------------------------------------------------------------------------------------------------------------

  • username and password
These parameters are used when signing into the Tableau online server

------------------------------------------------------------------------------------------------------------------------------------------


  • Data source name:

In the Tableau online server the name of the data source can be identified

------------------------------------------------------------------------------------------------------------------------------------------


Given that the python scripts have been located in C:\location\ the command for the Extract Refresh package will be as follows:

Finally save and deploy the package.


Command to copy.

Working directory: E:\Python36-32\

Command: E:\Python36-32\python.exe c:\Expectus\Tableau_Refresh_Extract\Refresh_tableau_online_extract.py --user "username" --pw "password" --url "site url" --site "site name" --datasource "datasource name"