Skip to content

Commit

Permalink
add checks on cron jobs and flushes redis on exceptions (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-script authored Jan 16, 2024
1 parent e5d47fd commit dfccc6e
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 21 deletions.
42 changes: 29 additions & 13 deletions cronjobs/cron.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from redis_functions import setPrimaryEndpoint
from redis_functions import setSecondaryEndpoint
from redis_functions import setTertiaryEndpoint
from redis_functions import flushChains


@total_ordering
Expand Down Expand Up @@ -195,21 +196,36 @@ def process_chain(chain: str, chain_info):
def main():
global running
threads = []
attempt = 0
while running:
chain_data = get_chain_config()
chain_info = get_chains_info(chain_data)
start_time = time.time()
for chain in chain_info:
t = Thread(target=process_chain, args=(chain, chain_info, ))
t.start()
threads.append(t)

for t in threads:
t.join()
try:
print('Getting chain config...')
chain_data = get_chain_config()
chain_info = get_chains_info(chain_data)
start_time = time.time()
for chain in chain_info:
t = Thread(target=process_chain, args=(chain, chain_info, ))
t.start()
threads.append(t)

for t in threads:
t.join()

print(f'Time used: {time.time() - start_time}')
threads = []
attempt = 0
time.sleep(5)

except Exception as e:
print('Failed to get chain config, flushing redis and trying again')
print(e)
attempt += 1
flushChains()
if attempt > 5:
time.sleep(5)



print(f'Time used: {time.time() - start_time}')
threads = []
time.sleep(5)


def signal_handler(sig, frame):
Expand Down
28 changes: 20 additions & 8 deletions cronjobs/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from github import get_tokens
from helpers import get_erc20_coins
from redis_functions import redisSetPrice, redisSetEvmosChange
from redis_functions import redisSetPrice, redisSetEvmosChange, flushTokens


def get_evmos_change():
Expand Down Expand Up @@ -49,14 +49,26 @@ def process_assets(prices):

def main():
global running
attempt = 0
while running:
tracked_tokens = get_tokens()
erc20_module_coins = get_erc20_coins(tracked_tokens)
print('Getting prices...')
prices = get_prices("usd", erc20_module_coins)
get_evmos_change()
process_assets(prices)
time.sleep(300)
try:
tracked_tokens = get_tokens()
erc20_module_coins = get_erc20_coins(tracked_tokens)
print('Getting prices...')
prices = get_prices("usd", erc20_module_coins)
get_evmos_change()
process_assets(prices)
attempt = 0
time.sleep(300)
except Exception as e:
print('Failed to get prices, trying again')
print(e)
attempt += 1
flushTokens()
if attempt > 5:
time.sleep(5)




def signal_handler(sig, frame):
Expand Down
7 changes: 7 additions & 0 deletions cronjobs/redis_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,10 @@ def getChains():
if not value:
return None
return json.loads(value)


def flushChains():
r.delete(networkConfig)

def flushTokens():
r.delete(erc20TokensDirectoryKey)

0 comments on commit dfccc6e

Please sign in to comment.