Port source dashboard processes to async

This commit is contained in:
Mark Veidemanis 2022-05-02 18:20:50 +01:00
parent fba0aab966
commit 789e27d627
Signed by: m
GPG Key ID: 5ACFCEED46C0904F
3 changed files with 42 additions and 24 deletions

View File

@ -1,6 +1,7 @@
# Twisted/Klein imports
from twisted.internet.task import LoopingCall
from twisted.internet.threads import deferToThread
from twisted.internet.defer import inlineCallbacks
# Other library imports
from json import loads
@ -13,6 +14,8 @@ from datetime import datetime
from settings import settings
import util
# import sources.local
class Agora(util.Base):
"""
@ -41,15 +44,24 @@ class Agora(util.Base):
"""
Set up the LoopingCall to get all active trades and messages.
"""
self.loop_check()
self.log.debug("Setting up loops.")
self.lc_dash = LoopingCall(self.loop_check)
self.lc_dash.start(int(settings.Agora.RefreshSec))
if settings.Agora.Cheat == "1":
self.lc_cheat = LoopingCall(self.run_cheat_in_thread)
self.lc_cheat.start(int(settings.Agora.CheatSec))
self.log.debug("Finished setting up loops.")
@util.handle_exceptions
def wrap_dashboard(self):
dash = self.agora.dashboard_seller()
@inlineCallbacks
def got_dashboard(self, dash):
dash_tmp = yield self.wrap_dashboard(dash)
self.dashboard_hook(dash_tmp)
@inlineCallbacks
def wrap_dashboard(self, dash=None): # backwards compatibility with TX
if not dash:
dash = yield self.agora.dashboard_seller()
if dash is None:
return False
if dash is False:
@ -72,16 +84,14 @@ class Agora(util.Base):
"""
Calls hooks to parse dashboard info and get all contact messages.
"""
dash_tmp = self.wrap_dashboard()
# Call dashboard hooks
self.dashboard_hook(dash_tmp)
d = self.agora.dashboard_seller()
d.addCallback(self.got_dashboard)
# Get recent messages
self.get_recent_messages()
return dash_tmp
m = self.agora.recent_messages()
m.addCallback(self.got_recent_messages)
def get_dashboard(self):
def get_dashboard_irc(self):
"""
Get dashboard helper for IRC only.
"""
@ -157,13 +167,11 @@ class Agora(util.Base):
current_trades.append(reference)
self.tx.cleanup(current_trades)
@util.handle_exceptions
def get_recent_messages(self, send_irc=True):
def got_recent_messages(self, messages, send_irc=True):
"""
Get recent messages.
"""
messages_tmp = {}
messages = self.agora.recent_messages()
if messages is False:
return False
if not messages["success"]:

0
handler/sources/local.py Normal file
View File

View File

@ -1,6 +1,7 @@
# Twisted/Klein imports
from twisted.internet.task import LoopingCall
from twisted.internet.threads import deferToThread
from twisted.internet.defer import inlineCallbacks
# Other library imports
from json import loads
@ -13,6 +14,8 @@ from datetime import datetime
from settings import settings
import util
# import sources.local
class LBTC(util.Base):
"""
@ -41,15 +44,25 @@ class LBTC(util.Base):
"""
Set up the LoopingCall to get all active trades and messages.
"""
self.log.debug("Running loop check.")
self.loop_check()
self.log.debug("Setting up loops.")
self.lc_dash = LoopingCall(self.loop_check)
self.lc_dash.start(int(settings.LocalBitcoins.RefreshSec))
if settings.LocalBitcoins.Cheat == "1":
self.lc_cheat = LoopingCall(self.run_cheat_in_thread)
self.lc_cheat.start(int(settings.LocalBitcoins.CheatSec))
self.log.debug("Finished setting up loops.")
@inlineCallbacks
def got_dashboard(self, dash):
dash_tmp = yield self.wrap_dashboard(dash)
self.dashboard_hook(dash_tmp)
@util.handle_exceptions
def wrap_dashboard(self):
dash = self.lbtc.dashboard() # no dashboard_seller for lbtc
def wrap_dashboard(self, dash=None): # backwards compatibility with TX
if not dash:
dash = self.lbtc.dashboard() # no dashboard_seller for lbtc
if dash is None:
return False
if dash is False:
@ -72,16 +85,14 @@ class LBTC(util.Base):
"""
Calls hooks to parse dashboard info and get all contact messages.
"""
dash_tmp = self.wrap_dashboard()
# Call dashboard hooks
self.dashboard_hook(dash_tmp)
d = self.lbtc.dashboard()
d.addCallback(self.got_dashboard)
# Get recent messages
self.get_recent_messages()
return dash_tmp
m = self.lbtc.recent_messages()
m.addCallback(self.got_recent_messages)
def get_dashboard(self):
def get_dashboard_irc(self):
"""
Get dashboard helper for IRC only.
"""
@ -154,12 +165,11 @@ class LBTC(util.Base):
self.tx.cleanup(current_trades)
@util.handle_exceptions
def get_recent_messages(self, send_irc=True):
def got_recent_messages(self, messages, send_irc=True):
"""
Get recent messages.
"""
messages_tmp = {}
messages = self.lbtc.recent_messages()
if messages is False:
return False
if not messages["success"]: