Skip to content

Commit 51bbed6

Browse files
authored
v0.22.1 (#339)
* filesystem huey * bump servestatic
1 parent 933e2e4 commit 51bbed6

8 files changed

Lines changed: 46 additions & 53 deletions

File tree

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.22.0
1+
0.22.1

conreq/__init__.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Monkey patch Huey's filelock implementation to add Windows support.
2+
import os
3+
import sys
4+
5+
6+
class FileLock:
7+
"""Operating system agnostic file lock implementation using os.open and os.close."""
8+
9+
def __init__(self, filename):
10+
self.filename = filename
11+
self.fd = None
12+
13+
dirname = os.path.dirname(filename)
14+
if not os.path.exists(dirname):
15+
os.makedirs(dirname)
16+
elif os.path.exists(self.filename):
17+
os.unlink(self.filename)
18+
19+
def acquire(self):
20+
flags = os.O_CREAT | os.O_TRUNC | os.O_RDWR
21+
self.fd = os.open(self.filename, flags)
22+
23+
def release(self):
24+
if self.fd is not None:
25+
fd, self.fd = self.fd, None
26+
os.close(fd)
27+
28+
def __enter__(self):
29+
self.acquire()
30+
return self
31+
32+
def __exit__(self, exc_type, exc_val, exc_tb):
33+
self.release()
34+
35+
36+
if sys.platform == "win32":
37+
import huey.utils
38+
39+
huey.utils.FileLock = FileLock

conreq/core/base/management/commands/preconfig_conreq.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
BASE_DIR = getattr(settings, "BASE_DIR")
1414
DATA_DIR = getattr(settings, "DATA_DIR")
1515
DATABASES = getattr(settings, "DATABASES")
16-
HUEY_FILENAME = getattr(settings, "HUEY_FILENAME")
1716

1817

1918
class Command(BaseCommand):
@@ -34,12 +33,6 @@ def handle(self, *args, **options):
3433
database = DATABASES["default"]["NAME"]
3534
self.setup_sqlite_database(database, "Conreq", uid, gid, no_perms)
3635

37-
# Background task database
38-
if HUEY_FILENAME:
39-
self.setup_sqlite_database(
40-
HUEY_FILENAME, "Background Task", uid, gid, no_perms
41-
)
42-
4336
if DEBUG:
4437
# Migrate silk due to their wonky dev choices
4538
call_command("makemigrations", "silk")

conreq/core/base/management/commands/run_conreq.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
UVICORN_CONFIG = os.path.join(getattr(settings, "DATA_DIR"), "uvicorn.env")
1818
DEBUG = get_debug()
19-
HUEY_FILENAME = getattr(settings, "HUEY_FILENAME")
2019
ACCESS_LOG_FILE = getattr(settings, "ACCESS_LOG_FILE")
2120

2221
_logger = getLogger(__name__)

conreq/core/base/static/js/events_click.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,6 @@ var quick_request_click_event = async function () {
133133
// Request the content
134134
post_json(btn.data("request-url"), params, function () {
135135
requested_toast_message();
136-
console.log(btn);
137136
btn.remove();
138137
ongoing_request = null;
139138
}).fail(async function () {

conreq/core/base/tasks.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,10 @@
1-
import sqlite3
2-
3-
from django.conf import settings
41
from django.db import connection
52
from huey import crontab
63
from huey.contrib.djhuey import db_periodic_task
74

85
from conreq.utils.environment import get_database_type
96

107
DB_ENGINE = get_database_type()
11-
HUEY_FILENAME = getattr(settings, "HUEY_FILENAME")
12-
13-
14-
@db_periodic_task(crontab(minute="0", hour="0", strict=True), expires=120)
15-
def huey_db_maintenance():
16-
with sqlite3.connect(HUEY_FILENAME) as cursor:
17-
cursor.execute(
18-
# Only keep the 1000 latest tasks
19-
"""DELETE FROM task
20-
WHERE id NOT IN (
21-
SELECT id
22-
FROM (
23-
SELECT id
24-
FROM task
25-
ORDER BY id DESC
26-
LIMIT 1000
27-
) foo
28-
);
29-
"""
30-
)
31-
with sqlite3.connect(HUEY_FILENAME) as cursor:
32-
cursor.execute("PRAGMA optimize;")
33-
cursor.execute("VACUUM;")
34-
cursor.execute("REINDEX;")
358

369

3710
if DB_ENGINE == "SQLITE3":

conreq/settings.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,25 +90,15 @@
9090
"css": ["compressor.filters.cssmin.rCSSMinFilter"],
9191
"js": ["compressor.filters.jsmin.JSMinFilter"],
9292
}
93-
HUEY_FILENAME = os.path.join(DATA_DIR, "bg_tasks.sqlite3")
9493
HUEY = {
95-
"name": "huey", # DB name for huey.
96-
"huey_class": "huey.SqliteHuey", # Huey implementation to use.
97-
"filename": HUEY_FILENAME, # Sqlite filename
98-
"results": True, # Whether to return values of tasks.
99-
"store_none": False, # Whether to store results of tasks that return None.
100-
"immediate": False, # If True, run tasks synchronously.
101-
"strict_fifo": True, # Utilize Sqlite AUTOINCREMENT to have unique task IDs
102-
"timeout": 10, # Seconds to wait when reading from the DB.
103-
"connection": {
104-
"isolation_level": "IMMEDIATE", # Use immediate transactions to allow sqlite to respect `timeout`.
105-
"cached_statements": 2000, # Number of pages to keep in memory.
106-
},
94+
"name": "huey",
95+
"huey_class": "huey.FileHuey",
96+
"path": os.path.join(DATA_DIR, "tasks"),
97+
"immediate": False,
98+
"use_thread_lock": True,
10799
"consumer": {
108100
"workers": os.cpu_count() or 8, # Number of worker processes/threads.
109-
"worker_type": "thread", # "thread" or "process"
110101
"initial_delay": 0.25, # Smallest polling interval
111-
"check_worker_health": True, # Whether to monitor worker health.
112102
},
113103
}
114104

requirements/main.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ titlecase==2.4.1
1919
tmdbsimple==2.9.1
2020
Twisted[tls,http2]==25.5.0
2121
tzlocal==5.3.1
22-
servestatic[brotli]==3.1.0
22+
servestatic[brotli]==4.1.0
2323
uvicorn[standard]==0.38.0
2424
attrs
2525
cffi

0 commit comments

Comments
 (0)