diff --git a/.github/workflows/python-package.yml b/.github/workflows/python-package.yml new file mode 100644 index 0000000..811ee4b --- /dev/null +++ b/.github/workflows/python-package.yml @@ -0,0 +1,41 @@ +# This workflow will install Python dependencies, run tests and lint with a variety of Python versions +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python + +name: Python package + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + python-version: ["3.8", "3.9", "3.10", "3.11"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v3 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + python -m pip install flake8 pytest + pip install -r requirements-all.txt + pip install . + - name: Lint with flake8 + run: | + # stop the build if there are Python syntax errors or undefined names + flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics + # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide + flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Test with pytest + run: | + pytest diff --git a/src/tomtom_api/priority_queue/lib.py b/src/tomtom_api/priority_queue/lib.py index 6d49dd9..de6416c 100644 --- a/src/tomtom_api/priority_queue/lib.py +++ b/src/tomtom_api/priority_queue/lib.py @@ -150,8 +150,7 @@ def priority_queue_update_job( item: QueueItem = db.get_filtered_items(uid=uid)[0] item.update(name, priority, cancel, payload) - db.update([item]) - db.write() + db.update([item], force_write=True) def pretty_print_queue(queue: List[QueueItem]) -> str: diff --git a/src/tomtom_api/priority_queue/models/database.py b/src/tomtom_api/priority_queue/models/database.py index 0172559..5be107d 100644 --- a/src/tomtom_api/priority_queue/models/database.py +++ b/src/tomtom_api/priority_queue/models/database.py @@ -40,6 +40,15 @@ def __init__(self): self.df = None self.read() + def _force_col_types(self) -> None: + for time_col in ['created_timestamp', + 'updated_timestamp', + 'submitted_timestamp', + 'completed_timestamp', + 'cancelled_timestamp', + 'error_timestamp']: + self.df[time_col] = pd.to_datetime(self.df[time_col]) + def read(self) -> None: """Read the file and store the content in the dataframe attribute. """ @@ -47,6 +56,7 @@ def read(self) -> None: self.df = pd.DataFrame(columns=self.columns) else: self.df = pd.read_parquet(self.file) + self._force_col_types() def write(self) -> None: """Write the content of the dataframe into the file. @@ -74,6 +84,7 @@ def add(self, item: QueueItem) -> None: data = {k: item.__dict__[k] for k in self.columns} data['report_type'] = item.payload.__class__.__name__ self.df = pd.concat([self.df, pd.DataFrame([data])]) + self._force_col_types() def get_next(self, n: int = 1) -> List[QueueItem]: """Get the list of the next element(s) @@ -225,3 +236,4 @@ def empty(self) -> None: """Empty the database """ self.df = pd.DataFrame(columns=self.columns) + self._force_col_types()