Skip to content

run long requests on second thread #1212

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 15 commits into from
Apr 19, 2023
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ celerybeat-schedule

# dotenv
.env
env.py

# virtualenv
venv/
Expand Down
10 changes: 3 additions & 7 deletions samples/add_default_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
def main():
parser = argparse.ArgumentParser(description="Add workbook default permissions for a given project.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/create_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,10 @@
def main():
parser = argparse.ArgumentParser(description="Creates a sample user group.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/create_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,10 @@ def create_project(server, project_item, samples=False):
def main():
parser = argparse.ArgumentParser(description="Create new projects.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/create_schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
def main():
parser = argparse.ArgumentParser(description="Creates sample schedules for each type of frequency.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/explore_datasource.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@
def main():
parser = argparse.ArgumentParser(description="Explore datasource functions supported by the Server API.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/explore_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
def main():
parser = argparse.ArgumentParser(description="Explore site updates by the Server API.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/explore_webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
def main():
parser = argparse.ArgumentParser(description="Explore webhook functions supported by the Server API.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/explore_workbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
def main():
parser = argparse.ArgumentParser(description="Explore workbook functions supported by the Server API.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
def main():
parser = argparse.ArgumentParser(description="Export a view as an image, PDF, or CSV")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/extracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,10 @@
def main():
parser = argparse.ArgumentParser(description="Explore extract functions supported by the Server API.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", help="site name")
parser.add_argument(
"--token-name", "-tn", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-tv", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-tn", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-tv", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/filter_sort_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,10 @@ def create_example_group(group_name="Example Group", server=None):
def main():
parser = argparse.ArgumentParser(description="Filter and sort groups.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/filter_sort_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ def create_example_project(
def main():
parser = argparse.ArgumentParser(description="Filter and sort projects.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
14 changes: 5 additions & 9 deletions samples/initialize_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
def main():
parser = argparse.ArgumentParser(description="Initialize a server with content.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand All @@ -29,8 +25,8 @@ def main():
help="desired logging level (set to error by default)",
)
# Options specific to this sample
parser.add_argument("--datasources-folder", "-df", required=True, help="folder containing datasources")
parser.add_argument("--workbooks-folder", "-wf", required=True, help="folder containing workbooks")
parser.add_argument("--datasources-folder", "-df", help="folder containing datasources")
parser.add_argument("--workbooks-folder", "-wf", help="folder containing workbooks")
parser.add_argument("--project", required=False, default="Default", help="project to use")

args = parser.parse_args()
Expand Down
10 changes: 3 additions & 7 deletions samples/kill_all_jobs.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,10 @@
def main():
parser = argparse.ArgumentParser(description="Cancel all of the running background jobs.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-p", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-p", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
10 changes: 3 additions & 7 deletions samples/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,10 @@
def main():
parser = argparse.ArgumentParser(description="List out the names and LUIDs for different resource types.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-n", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-n", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
21 changes: 15 additions & 6 deletions samples/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import logging

import tableauserverclient as TSC
import env


# If a sample has additional arguments, then it should copy this code and insert them after the call to
Expand All @@ -18,10 +19,15 @@ def set_up_and_log_in():
parser = argparse.ArgumentParser(description="Logs in to the server.")
sample_define_common_options(parser)
args = parser.parse_args()

# Set logging level based on user input, or error by default.
logging_level = getattr(logging, args.logging_level.upper())
logging.basicConfig(level=logging_level)
if not args.server:
args.server = env.server
if not args.site:
args.site = env.site
if not args.token_name:
args.token_name = env.token_name
if not args.token_value:
args.token_value = env.token_value
args.logging_level = "debug"

server = sample_connect_to_server(args)
print(server.server_info.get())
Expand All @@ -30,9 +36,9 @@ def set_up_and_log_in():

def sample_define_common_options(parser):
# Common options; please keep these in sync across all samples by copying or calling this method directly
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-t", help="site name")
auth = parser.add_mutually_exclusive_group(required=True)
auth = parser.add_mutually_exclusive_group(required=False)
auth.add_argument("--token-name", "-tn", help="name of the personal access token used to sign into the server")
auth.add_argument("--username", "-u", help="username to sign into the server")

Expand Down Expand Up @@ -73,6 +79,9 @@ def sample_connect_to_server(args):
# Make sure we use an updated version of the rest apis, and pass in our cert handling choice
server = TSC.Server(args.server, use_server_version=True, http_options={"verify": check_ssl_certificate})
server.auth.sign_in(tableau_auth)
server.version = "2.6"
new_site: TSC.SiteItem = TSC.SiteItem("cdnear", content_url=env.site)
server.auth.switch_site(new_site)
print("Logged in successfully")

return server
Expand Down
10 changes: 3 additions & 7 deletions samples/metadata_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,10 @@
def main():
parser = argparse.ArgumentParser(description="Use the metadata API to get information on a published data source.")
# Common options; please keep those in sync across all samples
parser.add_argument("--server", "-s", required=True, help="server address")
parser.add_argument("--server", "-s", help="server address")
parser.add_argument("--site", "-S", help="site name")
parser.add_argument(
"--token-name", "-n", required=True, help="name of the personal access token used to sign into the server"
)
parser.add_argument(
"--token-value", "-v", required=True, help="value of the personal access token used to sign into the server"
)
parser.add_argument("--token-name", "-n", help="name of the personal access token used to sign into the server")
parser.add_argument("--token-value", "-v", help="value of the personal access token used to sign into the server")
parser.add_argument(
"--logging-level",
"-l",
Expand Down
Loading