Merge pull request #3184 from InspectorCaracal/ticker-save-refactor
Minor refactor for TickerHandler.save()
This commit is contained in:
commit
06cfc7b01e
1 changed files with 14 additions and 18 deletions
|
|
@ -411,25 +411,21 @@ class TickerHandler(object):
|
||||||
for interval, ticker in self.ticker_pool.tickers.items()
|
for interval, ticker in self.ticker_pool.tickers.items()
|
||||||
)
|
)
|
||||||
|
|
||||||
# remove any subscriptions that lost its object in the interim
|
to_save = {}
|
||||||
to_save = {
|
|
||||||
store_key: (args, kwargs)
|
|
||||||
for store_key, (args, kwargs) in self.ticker_storage.items()
|
|
||||||
if (
|
|
||||||
(
|
|
||||||
store_key[1]
|
|
||||||
and ("_obj" in kwargs and kwargs["_obj"].pk)
|
|
||||||
and hasattr(kwargs["_obj"], store_key[1])
|
|
||||||
)
|
|
||||||
or store_key[2] # a valid method with existing obj
|
|
||||||
)
|
|
||||||
} # a path given
|
|
||||||
|
|
||||||
# update the timers for the tickers
|
# remove any subscription that lost its object and update the timers for the tickers
|
||||||
for store_key, (args, kwargs) in to_save.items():
|
for store_key, (args, kwargs) in self.ticker_storage.items():
|
||||||
interval = store_key[1]
|
# unpack the store_key to reference its parts
|
||||||
# this is a mutable, so it's updated in-place in ticker_storage
|
packedobj, callfunc, path, interval, idstring, persistent = store_key
|
||||||
kwargs["_start_delay"] = start_delays.get(interval, None)
|
# verify that there's a valid obj+method or function path
|
||||||
|
if (
|
||||||
|
callfunc
|
||||||
|
and ("_obj" in kwargs and kwargs["_obj"].pk)
|
||||||
|
and hasattr(kwargs["_obj"], callfunc)
|
||||||
|
) or path:
|
||||||
|
# this is a mutable, so it's updated in-place in ticker_storage
|
||||||
|
kwargs["_start_delay"] = start_delays.get(interval, None)
|
||||||
|
to_save[store_key] = (args, kwargs)
|
||||||
ServerConfig.objects.conf(key=self.save_name, value=dbserialize(to_save))
|
ServerConfig.objects.conf(key=self.save_name, value=dbserialize(to_save))
|
||||||
else:
|
else:
|
||||||
# make sure we have nothing lingering in the database
|
# make sure we have nothing lingering in the database
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue