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 #1

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
9 changes: 2 additions & 7 deletions saq/queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,9 +514,7 @@ async def apply(
kwargs: Same as Queue.enqueue
"""
results = await self.map(job_or_func, timeout=timeout, iter_kwargs=[kwargs])
if results:
return results[0]
return None
return results[0] if results else None
Copy link
Author

Choose a reason for hiding this comment

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

Function Queue.apply refactored with the following changes:


async def map(
self,
Expand Down Expand Up @@ -569,10 +567,7 @@ async def callback(job_key: str, status: Status) -> bool:
if status in UNSUCCESSFUL_TERMINAL_STATUSES and not return_exceptions:
return True

if not pending_job_keys:
return True

return False
return not pending_job_keys
Comment on lines -572 to +570
Copy link
Author

Choose a reason for hiding this comment

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

Function Queue.map refactored with the following changes:


# Start listening before we enqueue the jobs.
# This ensures we don't miss any updates.
Expand Down
7 changes: 2 additions & 5 deletions saq/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ async def _get_job(request: Request) -> Job:
async def exceptions(request: Request, handler: Handler) -> StreamResponse:
if request.path.startswith("/api"):
try:
resp = await handler(request)
return resp
return await handler(request)
Copy link
Author

Choose a reason for hiding this comment

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

Function exceptions refactored with the following changes:

except Exception:
error = traceback.format_exc()
logging.error(error)
Expand All @@ -127,9 +126,7 @@ async def shutdown(app: Application) -> None:

def create_app(queues: list[Queue]) -> Application:
middlewares = [exceptions]
password = os.environ.get("AUTH_PASSWORD")

if password:
if password := os.environ.get("AUTH_PASSWORD"):
Comment on lines -130 to +129
Copy link
Author

Choose a reason for hiding this comment

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

Function create_app refactored with the following changes:

from aiohttp_basicauth import BasicAuthMiddleware # type:ignore[import]

user = os.environ.get("AUTH_USER", "admin")
Expand Down
2 changes: 1 addition & 1 deletion saq/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ async def shutdown(_app: Application) -> None:

async def async_check_health(queue: Queue) -> int:
info = await queue.info()
if not info.get("name") == queue.name:
if info.get("name") != queue.name:
Copy link
Author

Choose a reason for hiding this comment

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

Function async_check_health refactored with the following changes:

  • Simplify logical expression using De Morgan identities (de-morgan)

logger.warning("Health check failed")
status = 1
else:
Expand Down
4 changes: 1 addition & 3 deletions tests/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,7 @@ async def test_queues(self) -> None:
async with self.client.get("/api/queues") as resp:
self.assertEqual(resp.status, 200)
json = await resp.json()
self.assertEqual(
set(q["name"] for q in json["queues"]), {"queue1", "queue2"}
)
self.assertEqual({q["name"] for q in json["queues"]}, {"queue1", "queue2"})
Copy link
Author

Choose a reason for hiding this comment

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

Function TestWorker.test_queues refactored with the following changes:


async with self.client.get(f"/api/queues/{self.queue1.name}") as resp:
self.assertEqual(resp.status, 200)
Expand Down