Skip to content

Commit

Permalink
build: make the CI checks pass and solve small coding issues (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
12rambau authored Oct 31, 2023
2 parents d27f374 + 2b395c3 commit 9b8ac78
Show file tree
Hide file tree
Showing 21 changed files with 398 additions and 305 deletions.
4 changes: 2 additions & 2 deletions .copier-answers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ _commit: 0.1.5
_src_path: gh:12rambau/pypackage
author_email: [email protected]
author_first_name: LDC Research Repository
author_last_name: ''
author_orcid: ''
author_last_name: ""
author_orcid: ""
github_repo_name: geeservermap
github_user: Louis-Dreyfus-Comany
project_name: geeservermap
Expand Down
14 changes: 7 additions & 7 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"ghcr.io/devcontainers-contrib/features/nox:2": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
},
"postCreateCommand": "pre-commit install"
"name": "Python 3",
"image": "mcr.microsoft.com/devcontainers/python:1-3.11-bullseye",
"features": {
"ghcr.io/devcontainers-contrib/features/nox:2": {},
"ghcr.io/devcontainers-contrib/features/pre-commit:2": {}
},
"postCreateCommand": "pre-commit install"
}
3 changes: 1 addition & 2 deletions .github/workflows/pypackage_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: template update check
on:
workflow_dispatch:
schedule:
- cron: '0 0 1 * *' # Run at 00:00 on the first day of each month
- cron: "0 0 1 * *" # Run at 00:00 on the first day of each month

jobs:
check_version:
Expand Down Expand Up @@ -50,4 +50,3 @@ jobs:
> You may need to reinstall ``copier`` and ``jinja2-time`` if they are not available in your environment.
After solving the merging issues you can push back the changes to your main branch.
1 change: 0 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,3 @@ repos:
- id: check-merge-conflict
stages: [commit]
args: [--assume-in-merge]

11 changes: 0 additions & 11 deletions CITATION.cff

This file was deleted.

2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from geeservermap import app
"""TODO Missing docstring."""
15 changes: 10 additions & 5 deletions geeservermap/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# coding=utf-8
from ._version import __version__
from .map import Map
from .main import MESSAGES
from . import helpers
from .elements import layers
"""TODO Missing docstring."""

from . import helpers as helpers
from .elements import layers as layers
from .main import MESSAGES as MESSAGES
from .map import Map as Map

__version__ = "0.0.0"
__author__ = "LDC Research Repository"
__email__ = "[email protected]"
2 changes: 0 additions & 2 deletions geeservermap/_version.py

This file was deleted.

66 changes: 45 additions & 21 deletions geeservermap/async_jobs.py
Original file line number Diff line number Diff line change
@@ -1,80 +1,104 @@
from threading import Thread
"""TODO Missing docstring."""

import atexit
import uuid
import time
import uuid
from contextlib import suppress
from copy import deepcopy
from threading import Thread


class Async:
"""TODO Missing docstring."""

_INTERVAL = 60
_TIMEOUT = 300

def __init__(self):
"""TODO Missing docstring."""
self._jobs = {}
self.cleanup_running = False
atexit.register(self._terminate)

def _run_cleanup(self):
"""TODO Missing docstring."""
self.cleanup_thread = Thread(target=self._cleanup_timedout_jobs)
self.cleanup_thread.start()

# This MUST be called when flask wants to exit otherwise the process will hang for a while
def _terminate(self):
"""TODO Missing docstring."""
self._jobs = None
try:
with suppress(Exception):
self.cleanup_thread.join()
except:
pass

def get_job_result(self, job_id):
"""TODO Missing docstring."""
if not self._jobs:
return None
job = self._jobs.get(job_id)
if job['state'] in ['finished', 'failed']:
if job["state"] in ["finished", "failed"]:
self.remove_job(job)
return job

def _create_job(self):
job = { 'id': uuid.uuid4().hex, 'ready': False,
'result': None, 'created': time.time(),
'state': 'created', 'finished': None
}
self._jobs[job['id']] = job
"""TODO Missing docstring."""
job = {
"id": uuid.uuid4().hex,
"ready": False,
"result": None,
"created": time.time(),
"state": "created",
"finished": None,
}
self._jobs[job["id"]] = job
if not self.cleanup_running:
self._run_cleanup()
self.cleanup_running = True
return job

def _start_job(self, thread, job):
job['state'] = 'started'
"""TODO Missing docstring."""
job["state"] = "started"
thread.daemon = True
thread.start()

def _finish_job(self, job, result):
job['ready'] = True
job['state'] = 'finished'
"""TODO Missing docstring."""
job["ready"] = True
job["state"] = "finished"
if self._is_job_alive(job):
job['result'] = result
job['finished'] = time.time()
job["result"] = result
job["finished"] = time.time()

def remove_job(self, job):
if self._jobs and job['id'] in self._jobs:
"""TODO Missing docstring."""
if self._jobs and job["id"] in self._jobs:
# logger.info(f'removing job {job["id"]}')
del self._jobs[job['id']]
del self._jobs[job["id"]]

def _is_job_alive(self, job):
return self._jobs and job != None and job['id'] in self._jobs and job['ready'] != None
"""TODO Missing docstring."""
return (
self._jobs
and job is not None
and job["id"] in self._jobs
and job["ready"] is not None
)

# Iterate though jobs every minute and remove the stale ones
def _cleanup_timedout_jobs(self):
"""TODO Missing docstring."""
next_cleanup_time = time.time()
while self._jobs != None:
while self._jobs is not None:
time.sleep(5)
now = time.time()
proxy = deepcopy(self._jobs)
if proxy and now >= next_cleanup_time:
for job in proxy.values():
if job['state'] == 'finished' and (job['finished'] + self._TIMEOUT > now):
if job["state"] == "finished" and (
job["finished"] + self._TIMEOUT > now
):
self.remove_job(job)
next_cleanup_time = time.time() + self._INTERVAL
self.cleanup_running = False
Expand Down
1 change: 1 addition & 0 deletions geeservermap/calls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""TODO Missing docstring."""
4 changes: 3 additions & 1 deletion geeservermap/elements/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
from . import layers
"""TODO Missing docstring."""

from . import layers as layers
Loading

0 comments on commit 9b8ac78

Please sign in to comment.