process dev
This commit is contained in:
parent
f302846e4a
commit
23a081570d
1 changed files with 40 additions and 10 deletions
|
|
@ -57,13 +57,43 @@ def run_get_rates(
|
|||
) -> None:
|
||||
logger.info("Getting rates")
|
||||
|
||||
# Create process log object to track everything
|
||||
# Get rates
|
||||
## Derive API calls to run from passed inputs
|
||||
## Get hold of proper API client depending on whether we are dry running or acting serious
|
||||
## Do our thing and get rates or die tryin'
|
||||
# Output
|
||||
## Create proper output writer depending on parameters
|
||||
## Check writeability
|
||||
## Do our thing and output or die tryin'
|
||||
# Call it a day
|
||||
process_state = GetRatesProcessState(output=output)
|
||||
|
||||
rates_fetcher = get_rates_fetcher(process_state.fetcher_type)
|
||||
|
||||
try:
|
||||
rates = rates_fetcher.fetch()
|
||||
except Exception as e:
|
||||
process_state.record_rate_fetching_error(e)
|
||||
raise ConnectionError(f"Could not fetch rates. See logs.")
|
||||
|
||||
rates_writer = get_rates_writer(process_state.output_type)
|
||||
|
||||
try:
|
||||
rates_writer.write(rates)
|
||||
except Exception as e:
|
||||
process_state.record_rate_writing_error(e)
|
||||
raise Exception(f"Could not write rates. See logs.")
|
||||
|
||||
|
||||
class GetRatesProcessState:
|
||||
def __init__(self, output: str, dry_run: bool) -> None:
|
||||
self.writer_type = self._infer_writer_type(output)
|
||||
self.fetcher_type = self._infer_fetcher_type(dry_run)
|
||||
|
||||
@staticmethod
|
||||
def _infer_writer_type(output: str) -> str:
|
||||
output_is_csv_file_path = bool(pathlib.Path(output).suffix == ".csv")
|
||||
|
||||
if output_is_csv_file_path:
|
||||
return "csv_file"
|
||||
|
||||
raise ValueError(f"Don't know how to handle passed output: {output}")
|
||||
|
||||
@staticmethod
|
||||
def _infer_fetcher_type(dry_run: bool) -> str:
|
||||
if dry_run:
|
||||
return MockFetcher
|
||||
|
||||
if not dry_run:
|
||||
return XEFetcher
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue