andykr1k commited on
Commit
b701a8e
·
1 Parent(s): fed3132

New event loop added for sub thread

Browse files
Files changed (1) hide show
  1. main.py +8 -10
main.py CHANGED
@@ -10,6 +10,7 @@ import requests
10
  from fastapi import FastAPI
11
  import uvicorn
12
  import threading
 
13
 
14
  app = FastAPI()
15
 
@@ -271,6 +272,7 @@ def handle_groupreviewrequests_update(event_payload):
271
  send_notification(title, body, token, author_id, id, "post")
272
 
273
  def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
 
274
  URL = f"wss://{SUPABASE_ID}.supabase.co/realtime/v1/websocket?apikey={SUPABASE_KEY}&vsn=1.0.0"
275
 
276
  with ThreadPoolExecutor(max_workers=10) as executor:
@@ -283,8 +285,7 @@ def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
283
  channel_listlikes.join().on(
284
  "INSERT", lambda payload: executor.submit(handle_listlikes_update, payload))
285
 
286
- channel_listcomments = s.set_channel(
287
- "realtime:public:listcomments")
288
  channel_listcomments.join().on(
289
  "INSERT", lambda payload: executor.submit(handle_listcomments_update, payload))
290
 
@@ -292,13 +293,11 @@ def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
292
  channel_likes.join().on(
293
  "INSERT", lambda payload: executor.submit(handle_likes_update, payload))
294
 
295
- channel_replylikes = s.set_channel(
296
- "realtime:public:replylikes")
297
  channel_replylikes.join().on(
298
  "INSERT", lambda payload: executor.submit(handle_replylikes_update, payload))
299
 
300
- channel_commentlikes = s.set_channel(
301
- "realtime:public:commentlikes")
302
  channel_commentlikes.join().on(
303
  "INSERT", lambda payload: executor.submit(handle_commentlikes_update, payload))
304
 
@@ -314,8 +313,7 @@ def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
314
  channel_replies.join().on(
315
  "INSERT", lambda payload: executor.submit(handle_reply_update, payload))
316
 
317
- channel_listreplies = s.set_channel(
318
- "realtime:public:listreplies")
319
  channel_listreplies.join().on(
320
  "INSERT", lambda payload: executor.submit(handle_listreply_update, payload))
321
 
@@ -324,8 +322,8 @@ def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
324
  "INSERT", lambda payload: executor.submit(handle_message_update, payload))
325
 
326
  channel_posts = s.set_channel("realtime:public:posts")
327
- channel_posts.join().on("INSERT", lambda payload: executor.submit(
328
- handle_groupreviewrequests_update, payload))
329
 
330
  s.listen()
331
 
 
10
  from fastapi import FastAPI
11
  import uvicorn
12
  import threading
13
+ import asyncio
14
 
15
  app = FastAPI()
16
 
 
272
  send_notification(title, body, token, author_id, id, "post")
273
 
274
  def setup_likes_subscription(SUPABASE_ID, SUPABASE_KEY):
275
+ asyncio.set_event_loop(asyncio.new_event_loop())
276
  URL = f"wss://{SUPABASE_ID}.supabase.co/realtime/v1/websocket?apikey={SUPABASE_KEY}&vsn=1.0.0"
277
 
278
  with ThreadPoolExecutor(max_workers=10) as executor:
 
285
  channel_listlikes.join().on(
286
  "INSERT", lambda payload: executor.submit(handle_listlikes_update, payload))
287
 
288
+ channel_listcomments = s.set_channel("realtime:public:listcomments")
 
289
  channel_listcomments.join().on(
290
  "INSERT", lambda payload: executor.submit(handle_listcomments_update, payload))
291
 
 
293
  channel_likes.join().on(
294
  "INSERT", lambda payload: executor.submit(handle_likes_update, payload))
295
 
296
+ channel_replylikes = s.set_channel("realtime:public:replylikes")
 
297
  channel_replylikes.join().on(
298
  "INSERT", lambda payload: executor.submit(handle_replylikes_update, payload))
299
 
300
+ channel_commentlikes = s.set_channel("realtime:public:commentlikes")
 
301
  channel_commentlikes.join().on(
302
  "INSERT", lambda payload: executor.submit(handle_commentlikes_update, payload))
303
 
 
313
  channel_replies.join().on(
314
  "INSERT", lambda payload: executor.submit(handle_reply_update, payload))
315
 
316
+ channel_listreplies = s.set_channel("realtime:public:listreplies")
 
317
  channel_listreplies.join().on(
318
  "INSERT", lambda payload: executor.submit(handle_listreply_update, payload))
319
 
 
322
  "INSERT", lambda payload: executor.submit(handle_message_update, payload))
323
 
324
  channel_posts = s.set_channel("realtime:public:posts")
325
+ channel_posts.join().on(
326
+ "INSERT", lambda payload: executor.submit(handle_groupreviewrequests_update, payload))
327
 
328
  s.listen()
329