Skip to content

Commit

Permalink
Moving to multiprocessing instead of threads due to thread objectpath…
Browse files Browse the repository at this point in the history
… thread safety
  • Loading branch information
DMcP89 committed May 14, 2024
1 parent e3df561 commit 515951c
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions harambot/services/transaction_polling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import Pool
from playhouse.shortcuts import model_to_dict
from yahoo_oauth import OAuth2
from discord import SyncWebhook
Expand Down Expand Up @@ -40,15 +40,21 @@ def poll_transactions(guild: Guild):
guild.league_id,
guild.league_type,
)
transactions = YahooAPI.get_latest_waiver_transactions()
transactions = YahooAPI.get_transactions()
if transactions:
for transaction in transactions:
embed = embed_functions_dict[transaction["type"]](transaction)
webhook = SyncWebhook.from_url(guild.webhook_url)
webhook = SyncWebhook.from_url(guild.transaction_polling_webhook)
webhook.send(embed=embed)
time.sleep(random_int)
print(len(transactions))


with ThreadPoolExecutor(max_workers=5) as executor:
results = list(executor.map(poll_transactions, Guild.select()))
with Pool(5) as executor:
results = list(
executor.map(
poll_transactions,
Guild.select().where(
Guild.transaction_polling_service_enabled == 1
),
)
)

0 comments on commit 515951c

Please sign in to comment.