-
Notifications
You must be signed in to change notification settings - Fork 444
Add cancel job #299
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
Add cancel job #299
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0adccc7
initial checkin for get background jobs
graysonarts fefa23d
addressed code review feedback
graysonarts 0f23526
added cancel job
graysonarts 022b303
fixing whitespace issues
graysonarts 09ef2ff
addressing small nits in the sample and the docs
graysonarts 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#### | ||
# This script demonstrates how to kill all of the running jobs | ||
# | ||
# To run the script, you must have installed Python 2.7.X or 3.3 and later. | ||
#### | ||
|
||
import argparse | ||
import getpass | ||
import logging | ||
|
||
import tableauserverclient as TSC | ||
|
||
|
||
def main(): | ||
parser = argparse.ArgumentParser(description='Cancel all of the running background jobs') | ||
parser.add_argument('--server', '-s', required=True, help='server address') | ||
parser.add_argument('--site', '-S', default=None, help='site to log into, do not specify for default site') | ||
parser.add_argument('--username', '-u', required=True, help='username to sign into server') | ||
parser.add_argument('--password', '-p', default=None, help='password for the user') | ||
|
||
parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error', | ||
help='desired logging level (set to error by default)') | ||
|
||
args = parser.parse_args() | ||
|
||
if args.password is None: | ||
password = getpass.getpass("Password: ") | ||
else: | ||
password = args.password | ||
|
||
# Set logging level based on user input, or error by default | ||
logging_level = getattr(logging, args.logging_level.upper()) | ||
logging.basicConfig(level=logging_level) | ||
|
||
# SIGN IN | ||
tableau_auth = TSC.TableauAuth(args.username, password, args.site) | ||
server = TSC.Server(args.server, use_server_version=True) | ||
with server.auth.sign_in(tableau_auth): | ||
req = TSC.RequestOptions() | ||
|
||
req.filter.add(TSC.Filter("progress", TSC.RequestOptions.Operator.LessThanOrEqual, 0)) | ||
for job in TSC.Pager(server.jobs, request_opts=req): | ||
print(server.jobs.cancel(job.id), job.id, job.status, job.type) | ||
|
||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
from .endpoint import Endpoint, api | ||
from .. import JobItem, BackgroundJobItem, PaginationItem | ||
from ..request_options import RequestOptionsBase | ||
import logging | ||
|
||
logger = logging.getLogger('tableau.endpoint.jobs') | ||
|
@@ -17,12 +18,20 @@ def get(self, job_id=None, req_options=None): | |
import warnings | ||
warnings.warn("Jobs.get(job_id) is deprecated, update code to use Jobs.get_by_id(job_id)") | ||
return self.get_by_id(job_id) | ||
if isinstance(job_id, RequestOptionsBase): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm so sad. But customers will love the functionality! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah once we hit 1.0, we can remove this. |
||
req_options = job_id | ||
|
||
self.parent_srv.assert_at_least_version('3.1') | ||
server_response = self.get_request(self.baseurl, req_options) | ||
pagination_item = PaginationItem.from_response(server_response.content, self.parent_srv.namespace) | ||
jobs = BackgroundJobItem.from_response(server_response.content, self.parent_srv.namespace) | ||
return jobs, pagination_item | ||
|
||
@api(version='3.1') | ||
def cancel(self, job_id): | ||
url = '{0}/{1}'.format(self.baseurl, job_id) | ||
return self.put_request(url) | ||
|
||
@api(version='2.6') | ||
def get_by_id(self, job_id): | ||
logger.info('Query for information about job ' + job_id) | ||
|
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
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.
So cancel takes an empty (as in
b''
) PUT? Didn't run job take an empty<tsRequest/ >
?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.
yeah...