mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-12-23 03:31:07 +00:00
re-initialize Application in push workers for windows
This commit is contained in:
parent
dec7c6a674
commit
bd50baa639
|
@ -22,7 +22,7 @@ from .cache import get_cache
|
|||
from .config import Config
|
||||
from .database import get_database
|
||||
from .http_client import HttpClient
|
||||
from .misc import check_open_port, get_resource
|
||||
from .misc import IS_WINDOWS, check_open_port, get_resource
|
||||
from .template import Template
|
||||
from .views import VIEWS
|
||||
from .views.api import handle_api_path
|
||||
|
@ -296,9 +296,14 @@ class CacheCleanupThread(Thread):
|
|||
|
||||
class PushWorker(multiprocessing.Process):
|
||||
def __init__(self, queue: multiprocessing.Queue):
|
||||
if Application.DEFAULT is None:
|
||||
raise RuntimeError('Application not setup yet')
|
||||
|
||||
multiprocessing.Process.__init__(self)
|
||||
|
||||
self.queue = queue
|
||||
self.shutdown = multiprocessing.Event()
|
||||
self.path = Application.DEFAULT.config.path
|
||||
|
||||
|
||||
def stop(self) -> None:
|
||||
|
@ -310,8 +315,17 @@ class PushWorker(multiprocessing.Process):
|
|||
|
||||
|
||||
async def handle_queue(self) -> None:
|
||||
client = HttpClient()
|
||||
client.open()
|
||||
if IS_WINDOWS:
|
||||
app = Application(self.path)
|
||||
client = app.client
|
||||
|
||||
client.open()
|
||||
app.database.connect()
|
||||
app.cache.setup()
|
||||
|
||||
else:
|
||||
client = HttpClient()
|
||||
client.open()
|
||||
|
||||
while not self.shutdown.is_set():
|
||||
try:
|
||||
|
@ -325,6 +339,10 @@ class PushWorker(multiprocessing.Process):
|
|||
except Exception:
|
||||
traceback.print_exc()
|
||||
|
||||
if IS_WINDOWS:
|
||||
app.database.disconnect()
|
||||
app.cache.close()
|
||||
|
||||
await client.close()
|
||||
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
|||
import aputils
|
||||
import json
|
||||
import os
|
||||
import platform
|
||||
import socket
|
||||
import typing
|
||||
|
||||
|
@ -38,6 +39,7 @@ ResponseType = typing.TypedDict('ResponseType', {
|
|||
})
|
||||
|
||||
IS_DOCKER = bool(os.environ.get('DOCKER_RUNNING'))
|
||||
IS_WINDOWS = platform.system() == 'Windows'
|
||||
|
||||
MIMETYPES = {
|
||||
'activity': 'application/activity+json',
|
||||
|
|
Loading…
Reference in a new issue