Andrea Zucchelli
bce55b225f
Squashed commit of the following: commitf3c87deb32
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 23:47:36 2024 +0200 chore: refresh button commite7c831e0c2
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 23:37:56 2024 +0200 feat: wrapping up containers commite571b00c3d
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 21:27:52 2024 +0200 fix: sort out sub commit4a75d4561b
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 21:24:56 2024 +0200 fix: sort out sub commit3c1030a2fe
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 20:29:29 2024 +0200 chore: optimize image build commitf63d1b185b
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 20:28:11 2024 +0200 chore: optimize image build commit0d9a175438
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 20:26:16 2024 +0200 chore: optimize image build commitbb510718d2
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 20:08:22 2024 +0200 fix: toggle_connection commitb48a12c1f3
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 20:02:30 2024 +0200 fix: toggle_connection commit343c36002b
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 19:27:14 2024 +0200 fix: serialization commit880909912c
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 19:24:06 2024 +0200 fix: sync command commitfbabd0cfca
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 19:13:10 2024 +0200 fix: import Peer commit444f612452
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 19:09:28 2024 +0200 chore: use celery commit2f96991294
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 19:02:40 2024 +0200 fix: make gunicorn listen on 0.0.0.0 commit313f23e23c
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 18:59:22 2024 +0200 chore: docker stuff compat commitc17153112b
Author: Andrea Zucchelli <zukka77@gmail.com> Date: Sun Oct 13 18:55:39 2024 +0200 feat: celery decoupling
39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
import environ
|
|
from celery import Celery
|
|
from pywireguard.factory import Peer
|
|
from .wg_manager import WGManager
|
|
|
|
|
|
env = environ.Env(WG_INTERFACE=(str, "wg0"), CELERY_BROKER=(str, "redis://localhost"), CELERY_BACKEND=(str, "redis://localhost"))
|
|
environ.Env.read_env(".env")
|
|
WG_INTERFACE = env("WG_INTERFACE")
|
|
CELERY_BROKER = env("CELERY_BROKER")
|
|
CELERY_BACKEND = env("CELERY_BACKEND")
|
|
app = Celery("wg_manager_tasks", broker=CELERY_BROKER, backend=CELERY_BACKEND)
|
|
app.conf.event_serializer = "pickle" # this event_serializer is optional. somehow i missed this when writing this solution and it still worked without.
|
|
app.conf.task_serializer = "pickle"
|
|
app.conf.result_serializer = "pickle"
|
|
app.conf.accept_content = ["application/json", "application/x-python-serialize"]
|
|
|
|
|
|
@app.task(ignore_result=True)
|
|
def add_peer(peer: Peer):
|
|
wg = WGManager(WG_INTERFACE)
|
|
wg.add_peer(peer)
|
|
|
|
|
|
@app.task(ignore_result=True)
|
|
def remove_peer(peer: Peer):
|
|
wg = WGManager(WG_INTERFACE)
|
|
wg.remove_peer(peer)
|
|
|
|
|
|
@app.task
|
|
def get_peers() -> list[Peer]:
|
|
wg = WGManager(WG_INTERFACE)
|
|
return wg.get_peers()
|
|
|
|
|
|
@app.task
|
|
def ping() -> str:
|
|
return "pong"
|