-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored master branch #2
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,9 +19,7 @@ async def check_health(self, request): | |
|
||
# write response | ||
|
||
res_status = 200 | ||
|
||
return res_status | ||
return 200 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,14 +43,11 @@ def get(self, key, prefix=None): | |
stop=stop_after_delay(RETRY_DELAY_IN_SECONDS)) | ||
def get_all(self): | ||
try: | ||
only_kv_data = [] | ||
_, data = self.consul_client.kv.get(key='', recurse=True) | ||
for item in data: | ||
only_kv_data.append({ | ||
return [{ | ||
"Key": item['Key'], | ||
"Value": json.loads((item['Value'].decode('utf-8'))) | ||
}) | ||
return only_kv_data | ||
} for item in data] | ||
Comment on lines
-46
to
+50
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except ConnectionError as ex: | ||
self.connect() | ||
raise ex | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,29 +17,28 @@ class CoreModule(Module): | |
@provider | ||
def provide_consul_client(self) -> ConsulClient: | ||
"""innit consul client""" | ||
consul_client = ConsulClient(host=os.getenv('CONSUL_HOST', '127.0.0.1'), prefix='sites-checker-service') | ||
return consul_client | ||
return ConsulClient( | ||
host=os.getenv('CONSUL_HOST', '127.0.0.1'), | ||
prefix='sites-checker-service', | ||
) | ||
Comment on lines
-20
to
+23
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@singleton | ||
@provider | ||
def provide_postgres_client(self, | ||
conf_service: ConfigService | ||
) -> PostgresClient: | ||
"""innit Postgres client""" | ||
postgres_client = PostgresClient(dsn=conf_service.postgres_url) | ||
# TODO: check asyncio support | ||
# await postgres_client.connect() | ||
return postgres_client | ||
return PostgresClient(dsn=conf_service.postgres_url) | ||
Comment on lines
-29
to
+33
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
@singleton | ||
@provider | ||
def provide_logger(self) -> Logger: | ||
"""innit logger""" | ||
logger = get_logger( | ||
return get_logger( | ||
logger_name='SitesCheckerService', | ||
logger_format=LoggingFormat.JSON, | ||
logger_level=logging.INFO, | ||
logger_output=LoggingOutput.STDOUT, | ||
) | ||
|
||
return logger | ||
Comment on lines
-38
to
-45
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,8 +30,7 @@ def prepare(self, query, data): | |
def select(self, query): | ||
cursor = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) | ||
cursor.execute(query) | ||
for result in cursor.fetchall(): | ||
yield result | ||
yield from cursor.fetchall() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
cursor.close() | ||
|
||
|
||
|
@@ -73,8 +72,7 @@ def insert(self, sql): | |
cursor = self.conn.cursor(cursor_factory=psycopg2.extras.RealDictCursor) | ||
try: | ||
cursor.execute(sql) | ||
for result in cursor.fetchall(): | ||
yield result | ||
yield from cursor.fetchall() | ||
Comment on lines
-76
to
+75
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
except psycopg2.DatabaseError as ex: | ||
raise ex | ||
else: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,8 +13,7 @@ def add_interval_job(self, callback, interval: float): | |
self.scheduler.add_job(callback, 'interval', seconds=interval) | ||
|
||
def run_once(self, callback, args: list): | ||
job = self.scheduler.add_job(callback, 'date', args=args) | ||
return job | ||
return self.scheduler.add_job(callback, 'date', args=args) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
def start(self): | ||
self.scheduler = AsyncIOScheduler() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -37,12 +37,10 @@ def __init__(self, | |
async def status(self): | ||
status_code = 0 | ||
|
||
service_state = { | ||
return { | ||
'status_code': status_code, | ||
} | ||
|
||
return service_state | ||
Comment on lines
-40
to
-44
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
||
|
||
async def kill(self): | ||
""" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
ConsulClient.get_all
refactored with the following changes:list-comprehension
)inline-immediately-returned-variable
)