Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions sites-checker/Infra/scripts/consul_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

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:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

except ConnectionError as ex:
self.connect()
raise ex
Expand Down
4 changes: 1 addition & 3 deletions sites-checker/SitesCheckerService/api/health_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ async def check_health(self, request):

# write response

res_status = 200

return res_status
return 200
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function HealthCheckController.check_health refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)




Expand Down
7 changes: 2 additions & 5 deletions sites-checker/SitesCheckerService/core/consul_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

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:

  • Convert for loop into list comprehension (list-comprehension)
  • Inline variable that is immediately returned (inline-immediately-returned-variable)

except ConnectionError as ex:
self.connect()
raise ex
Expand Down
13 changes: 6 additions & 7 deletions sites-checker/SitesCheckerService/core/core_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CoreModule.provide_consul_client refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


@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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CoreModule.provide_postgres_client refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


@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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function CoreModule.provide_logger refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)

6 changes: 2 additions & 4 deletions sites-checker/SitesCheckerService/core/postgres_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostgresClient.select refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

cursor.close()


Expand Down Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function PostgresClient.insert refactored with the following changes:

  • Replace yield inside for loop with yield from (yield-from)

except psycopg2.DatabaseError as ex:
raise ex
else:
Expand Down
3 changes: 1 addition & 2 deletions sites-checker/SitesCheckerService/jobs/job_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function JobManager.run_once refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)


def start(self):
self.scheduler = AsyncIOScheduler()
Expand Down
4 changes: 1 addition & 3 deletions sites-checker/SitesCheckerService/sites_checker_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function SitesCheckerService.status refactored with the following changes:

  • Inline variable that is immediately returned (inline-immediately-returned-variable)



async def kill(self):
"""
Expand Down