mirror of
https://git.pleroma.social/pleroma/relay.git
synced 2024-11-22 22:48:00 +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 .config import Config
|
||||||
from .database import get_database
|
from .database import get_database
|
||||||
from .http_client import HttpClient
|
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 .template import Template
|
||||||
from .views import VIEWS
|
from .views import VIEWS
|
||||||
from .views.api import handle_api_path
|
from .views.api import handle_api_path
|
||||||
|
@ -296,9 +296,14 @@ class CacheCleanupThread(Thread):
|
||||||
|
|
||||||
class PushWorker(multiprocessing.Process):
|
class PushWorker(multiprocessing.Process):
|
||||||
def __init__(self, queue: multiprocessing.Queue):
|
def __init__(self, queue: multiprocessing.Queue):
|
||||||
|
if Application.DEFAULT is None:
|
||||||
|
raise RuntimeError('Application not setup yet')
|
||||||
|
|
||||||
multiprocessing.Process.__init__(self)
|
multiprocessing.Process.__init__(self)
|
||||||
|
|
||||||
self.queue = queue
|
self.queue = queue
|
||||||
self.shutdown = multiprocessing.Event()
|
self.shutdown = multiprocessing.Event()
|
||||||
|
self.path = Application.DEFAULT.config.path
|
||||||
|
|
||||||
|
|
||||||
def stop(self) -> None:
|
def stop(self) -> None:
|
||||||
|
@ -310,6 +315,15 @@ class PushWorker(multiprocessing.Process):
|
||||||
|
|
||||||
|
|
||||||
async def handle_queue(self) -> None:
|
async def handle_queue(self) -> None:
|
||||||
|
if IS_WINDOWS:
|
||||||
|
app = Application(self.path)
|
||||||
|
client = app.client
|
||||||
|
|
||||||
|
client.open()
|
||||||
|
app.database.connect()
|
||||||
|
app.cache.setup()
|
||||||
|
|
||||||
|
else:
|
||||||
client = HttpClient()
|
client = HttpClient()
|
||||||
client.open()
|
client.open()
|
||||||
|
|
||||||
|
@ -325,6 +339,10 @@ class PushWorker(multiprocessing.Process):
|
||||||
except Exception:
|
except Exception:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
|
|
||||||
|
if IS_WINDOWS:
|
||||||
|
app.database.disconnect()
|
||||||
|
app.cache.close()
|
||||||
|
|
||||||
await client.close()
|
await client.close()
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@ from __future__ import annotations
|
||||||
import aputils
|
import aputils
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
|
import platform
|
||||||
import socket
|
import socket
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
|
@ -38,6 +39,7 @@ ResponseType = typing.TypedDict('ResponseType', {
|
||||||
})
|
})
|
||||||
|
|
||||||
IS_DOCKER = bool(os.environ.get('DOCKER_RUNNING'))
|
IS_DOCKER = bool(os.environ.get('DOCKER_RUNNING'))
|
||||||
|
IS_WINDOWS = platform.system() == 'Windows'
|
||||||
|
|
||||||
MIMETYPES = {
|
MIMETYPES = {
|
||||||
'activity': 'application/activity+json',
|
'activity': 'application/activity+json',
|
||||||
|
|
Loading…
Reference in a new issue