Skip to content

Commit c2dbaf5

Browse files
Miscjarofgreen
authored andcommitted
Add code
1 parent 2f3ae54 commit c2dbaf5

File tree

86 files changed

+2589
-18
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+2589
-18
lines changed

.github/workflows/lint.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: Lint
2+
on: [push, pull_request]
3+
4+
jobs:
5+
lint:
6+
runs-on: ubuntu-latest
7+
steps:
8+
- uses: actions/checkout@v2
9+
- name: Setup python
10+
uses: actions/setup-python@v2
11+
with:
12+
python-version: 3.9
13+
architecture: x64
14+
- uses: actions/cache@v1
15+
with:
16+
path: ~/.cache/pip
17+
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements_dev.txt') }}-${{ matrix.python-version }}
18+
restore-keys: |
19+
${{ runner.os }}-pip-
20+
- run: pip install -e .[dev]
21+
- run: isort --check-only libcoveweb2 setup.py
22+
- run: black --check libcoveweb2 setup.py
23+
- run: flake8 libcoveweb2 setup.py
24+
- run: mypy --install-types --non-interactive -p libcoveweb2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
__pycache__
2+

LICENSE.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Cove - COnvert Validate & Explore
2+
=================================
3+
4+
Cove - COnvert Validate & Explore is free software designed to help people check data
5+
published to various different data standards.
6+
7+
Cove - COnvert Validate & Explore is free software: you can redistribute it and/or modify
8+
it under the terms of the GNU Affero General Public License as published by
9+
the Free Software Foundation, either version 3 of the License, or
10+
(at your option) any later version.
11+
12+
Cove - COnvert Validate & Explore is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU Affero General Public License for more details.
16+
17+
You should have received a copy of the GNU Affero General Public License
18+
along with Cove - COnvert Validate & Explore. If not, see <http://www.gnu.org/licenses/>.

libcoveweb2/admin.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# from django.contrib import admin
2+
3+
# Register your models here.

libcoveweb2/apps.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from django.apps import AppConfig
2+
3+
4+
class Libcoveweb2Config(AppConfig):
5+
default_auto_field = "django.db.models.BigAutoField"
6+
name = "libcoveweb2"

libcoveweb2/background_worker.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import logging
2+
3+
from libcoveweb2.celery import app
4+
from libcoveweb2.process.utils import process_data_worker
5+
6+
logger = logging.getLogger(__name__)
7+
8+
9+
def process_supplied_data(id: str):
10+
"""Call to process some supplied data.
11+
Sends processing work to a worker so calling thread will get a return immediately
12+
(if Celery is configured properly)."""
13+
logger.info("Adding to Queue - process supplied data id " + str(id))
14+
_process_supplied_data_celery_task.delay(id)
15+
16+
17+
@app.task
18+
def _process_supplied_data_celery_task(id: str):
19+
process_data_worker(id)

libcoveweb2/celery.py

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import os
2+
3+
from celery import Celery
4+
5+
# set the default Django settings module for the 'celery' program.
6+
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cove_project.settings")
7+
8+
# Create Celery App
9+
app = Celery("tasks")
10+
11+
# Using a string here means the worker doesn't have to serialize
12+
# the configuration object to child processes.
13+
# - namespace='CELERY' means all celery-related configuration keys
14+
# should have a `CELERY_` prefix.
15+
app.config_from_object("django.conf:settings", namespace="CELERY")
16+
17+
app.conf.update(
18+
# Set so producer of messages will eventually time out and not try for ever
19+
# This shouldn't ever apply on live; 20 is such a big number
20+
# But it might apply if tests are ever run badly,
21+
# and without this your tests is stuck in an infinite loop
22+
# (not great when it's run on someone's C.I.!)
23+
broker_transport_options={"max_retries": 20},
24+
)
25+
# Load task modules from all registered Django app configs.
26+
app.autodiscover_tasks()
27+
28+
29+
class CeleryInspector:
30+
def __init__(self):
31+
global app
32+
self._inspector = app.control.inspect()
33+
34+
def is_supplied_data_being_processed(self, id):
35+
data = self._inspector.active()
36+
if isinstance(data, dict):
37+
for worker, tasks in data.items():
38+
for task in tasks:
39+
if task.get("args", [])[0] == str(id):
40+
return True
41+
return False

libcoveweb2/context_processors.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from django.conf import settings
2+
3+
4+
def from_settings(request):
5+
context = {
6+
"input_methods": settings.COVE_CONFIG.get("input_methods", []),
7+
"app_verbose_name": settings.COVE_CONFIG.get("app_verbose_name", []),
8+
"piwik": getattr(settings, "PIWIK", {"dimension_map": {}}),
9+
"google_analytics_id": getattr(settings, "GOOGLE_ANALYTICS_ID", ""),
10+
"sentry_dsn": getattr(settings, "SENTRY_DSN", ""),
11+
"delete_files_after_days": getattr(settings, "DELETE_FILES_AFTER_DAYS", 7),
12+
}
13+
return context

libcoveweb2/forms.py

Whitespace-only changes.

libcoveweb2/management/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)