Updated crank-market so it can loop if the user wants to run it as a service.

This commit is contained in:
Geoff Taylor 2022-02-11 15:15:20 +00:00
parent a23a51a566
commit 8dce45ee43
1 changed files with 19 additions and 2 deletions

View File

@ -5,6 +5,8 @@ import logging
import os import os
import os.path import os.path
import sys import sys
import time
import traceback
from decimal import Decimal from decimal import Decimal
from solana.publickey import PublicKey from solana.publickey import PublicKey
@ -24,6 +26,11 @@ parser.add_argument(
default=Decimal(32), default=Decimal(32),
help="maximum number of events to be processed", help="maximum number of events to be processed",
) )
parser.add_argument(
"--pulse-interval",
type=float,
help="if specified, run in a loop pausing this number of seconds between each crank",
)
parser.add_argument( parser.add_argument(
"--account-address", "--account-address",
type=PublicKey, type=PublicKey,
@ -53,7 +60,17 @@ if market is None:
market_operations = mango.create_market_operations( market_operations = mango.create_market_operations(
context, wallet, account, market, args.dry_run context, wallet, account, market, args.dry_run
) )
crank = market_operations.crank(args.limit) if args.pulse_interval is None:
mango.output(crank) crank = market_operations.crank(args.limit)
mango.output(crank)
else:
while True:
try:
crank = market_operations.crank(args.limit)
mango.output(crank)
time.sleep(args.pulse_interval)
except Exception as exception:
logging.error(f"Pulse action failed: {traceback.format_exc()}")
mango.output(exception)
logging.info("Crank completed.") logging.info("Crank completed.")