10000 Schedule tasks by jacalata · Pull Request #2 · jacalata/server-client-python · GitHub
[go: up one dir, main page]

Skip to content

Schedule tasks #2

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Schedule tasks #2

wants to merge 2 commits into from

Conversation

jacalata
Copy link
Owner
@jacalata jacalata commented Dec 12, 2024

see what happens

Summary by Sourcery

Add support for scheduling and managing extract refresh tasks by introducing new classes and endpoints. Enhance error handling with a new exception class for response body errors.

New Features:

  • Introduce a new class ExtractRefreshTaskItem to represent extract refresh tasks, including properties for priority, refresh type, item type, and item ID.
  • Add a new Tasks class to the server module, which includes an ExtractRefreshes endpoint for handling extract refresh tasks.

Enhancements:

  • Add a new exception class ResponseBodyError to handle errors related to response bodies.

Copy link
sourcery-ai bot commented Dec 12, 2024

Reviewer's Guide by Sourcery

This PR implements task scheduling functionality by adding new classes and endpoints to handle extract refresh tasks. The implementation includes a task hierarchy with a base TaskItem class and a specialized ExtractRefreshTaskItem class for handling extract refresh operations on datasources and workbooks.

Class diagram for Tasks and ExtractRefreshes endpoints

classDiagram
    class Endpoint {
    }

    class ExtractRefreshes {
        - parent_srv
        + baseurl()
        + get_for_schedule(schedule_id, req_options)
    }

    class Tasks {
        - parent_srv
        - extract_refreshes
    }

    Endpoint <|-- ExtractRefreshes
    Endpoint <|-- Tasks
    Tasks o-- ExtractRefreshes
Loading

File-Level Changes

Change Details Files
Added new exception class for handling response body errors
  • Created ResponseBodyError exception class
tableauserverclient/models/exceptions.py
Implemented task scheduling core functionality
  • Created base TaskItem class with id and schedule_id properties
  • Added ExtractRefreshTaskItem class with priority, refresh type, and item type handling
  • Implemented XML response parsing for extract refresh tasks
  • Added validation for priority range (1-100)
  • Added validation for refresh types (FullRefresh, IncrementalRefresh)
  • Added validation for item types (Datasource, Workbook)
tableauserverclient/models/task_item.py
tableauserverclient/models/extract_refresh_task_item.py
tableauserverclient/models/item_types.py
Added new endpoint implementations for task management
  • Created Tasks endpoint class as main entry point for task operations
  • Implemented ExtractRefreshes endpoint for handling extract refresh operations
  • Added get_for_schedule method to retrieve tasks for a specific schedule
tableauserverclient/server/endpoint/tasks_endpoint.py
tableauserverclient/server/endpoint/extract_refreshes_endpoint.py
Integrated task functionality into server class
  • Added tasks property to Server class initialization
tableauserverclient/server/server.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time. You can also use
    this command to specify where the summary should be inserted.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @jacalata - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Please provide a proper description of the changes and purpose of this PR. 'see what happens' is not sufficient documentation.
  • Test coverage is missing for the new task scheduling functionality. Please add appropriate unit tests.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

# a REST API. Possibly we could be more vigilant in hiding the constructor
def __init__(self, id, schedule_id, priority, refresh_type, item_type, item_id):
super(ExtractRefreshTaskItem, self).__init__(id, schedule_id)
self.priority = priority
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): The 'type' parameter in init is assigned to self.type but never used elsewhere in the class

This unused assignment could lead to confusion and potential bugs. Consider removing it if not needed.

@staticmethod
def _parse_element(extract_tag):
id = extract_tag.get('id')
priority = int(extract_tag.get('priority'))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: Missing error handling for malformed XML attributes in _parse_element

Add error handling for cases where priority is not a valid integer or other attributes are missing/malformed.

@item_type.setter
def item_type(self, value):
# Check that it is Datasource or Workbook
if not (value in [ItemTypes.Datasource, ItemTypes.Workbook]):
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Simplify logical expression using De Morgan identities (de-morgan)

Suggested change
if not (value in [ItemTypes.Datasource, ItemTypes.Workbook]):
if value not in [ItemTypes.Datasource, ItemTypes.Workbook]:


@classmethod
def from_response(cls, resp, schedule_id):
tasks_items = list()
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (code-quality): Replace list() with [] (list-literal)

Suggested change
tasks_items = list()
tasks_items = []


ExplanationThe most concise and Pythonic way to create a list is to use the [] notation.

This fits in with the way we create lists with elements, saving a bit of mental
energy that might be taken up with thinking about two different ways of creating
lists.

x = ["first", "second"]

Doing things this way has the added advantage of being a nice little performance
improvement.

Here are the timings before and after the change:

$ python3 -m timeit "x = list()"
5000000 loops, best of 5: 63.3 nsec per loop
$ python3 -m timeit "x = []"
20000000 loops, best of 5: 15.8 nsec per loop

Similar reasoning and performance results hold for replacing dict() with {}.


@staticmethod
def _parse_element(extract_tag):
id = extract_tag.get('id')
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (code-quality): Don't assign to builtin variable id (avoid-builtin-shadow)


ExplanationPython has a number of builtin variables: functions and constants that
form a part of the language, such as list, getattr, and type
(See https://docs.python.org/3/library/functions.html).
It is valid, in the language, to re-bind such variables:

list = [1, 2, 3]

However, this is considered poor practice.

  • It will confuse other developers.
  • It will confuse syntax highlighters and linters.
  • It means you can no longer use that builtin for its original purpose.

How can you solve this?

Rename the variable something more specific, such as integers.
In a pinch, my_list and similar names are colloquially-recognized
placeholders.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0