Skip to content

Commit

Permalink
FW-573: Added backoff decorators (#14)
Browse files Browse the repository at this point in the history
* Added backoff decorators
  • Loading branch information
lewis-chambers authored Jan 29, 2025
1 parent 480c57b commit 3253961
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 0 deletions.
54 changes: 54 additions & 0 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/bin/sh
#
# An example hook script to verify what is about to be committed.
# Called by "git commit" with no arguments. The hook should
# exit with non-zero status after issuing an appropriate message if
# it wants to stop the commit.
#
# To enable this hook, rename this file to "pre-commit".

if git rev-parse --verify HEAD >/dev/null 2>&1
then
against=HEAD
else
# Initial commit: diff against an empty tree object
against=$(git hash-object -t tree /dev/null)
fi


# Redirect output to stderr.
exec 1>&2

RED='\033[0;31m'
NC='\033[0m' # No Color
format_err=0
check_err=0
err=0

echo 'Running "ruff format --check"'
ruff format --check

if [ "$?" -eq 1 ]; then
format_err=1
err=1
fi

echo 'Running "ruff check"'
ruff check

if [ "$?" -eq 1 ]; then
check_err=1
err=1
fi

if [ "${format_err}" -eq 1 ] ; then
echo "${RED}Run \"ruff format\" before committing${NC}"
fi

if [ "${check_err}" -eq 1 ] ; then
echo "${RED}Correct ruff errors before committing${NC}"
fi

if [ "${err}" -eq 1 ] ; then
exit 1
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.*/*
!.githooks/*
**/__pycache__/*
*.docx
build/*
Expand Down
5 changes: 5 additions & 0 deletions src/iotswarm/livecosmos/liveupload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
from datetime import datetime, timedelta
from typing import List, Optional

import backoff
import oracledb
from awscrt.exceptions import AwsCrtError
from driutils.io.aws import S3Writer

from iotswarm.db import Oracle
Expand Down Expand Up @@ -103,6 +106,7 @@ async def get_latest_payloads(self) -> List[CR1000XPayload]:
# Flatten lists and return
return [item for row in payloads for item in row]

@backoff.on_exception(backoff.expo, oracledb.Error, max_time=60, logger=logger)
async def _get_latest_payloads_for_site(self, site: str) -> List[CR1000XPayload]:
"""Gets all new payloads from the Oracle table for a given site. If the
site is present inside the `state` the latest data is taken from it, if not
Expand Down Expand Up @@ -152,6 +156,7 @@ def _get_s3_key(self, site_id: str, object_name: str) -> str:

return key

@backoff.on_exception(backoff.expo, AwsCrtError, max_time=60, logger=logger)
def send_payload(self, payload: CR1000XPayload, s3_writer: S3Writer) -> None:
"""Sends the payload to AWS and writes the state to file
Expand Down

0 comments on commit 3253961

Please sign in to comment.