Sonar refactor: tasks.py

What does this MR do and why?

Resolve as many as possible of the Sonar issues in tasks.py.

I think that the current state of Crafty makes resolving all issues current unfeasible, details below.

Does:

  • isort tasks.py.
  • Convert repeated strings to constants.
  • Create typed dicts for better type hints around commonly used dicts in the file.
  • Add missing type hints and docstrings to touched functions.
  • Simplify overly complicated function logic with helper functions and early returns.
  • Narrow scope of bare excepts (where possible).
  • Break check_for_updates into three smaller functions called by crafty_maintenance. This is now a more future-proof shape for functions that we want to run on a regular schedule. It now owns the Gravatar pfp updates and cleaning of temp and import directories.

Issues that I do no think can currently be fixed:

  • Line 231, bare except. This except catches error after trying to stop all servers. A quick review of the call stack shows that it is currently catching around ~10 errors. This part of Crafty must fail-safe so all error classes must be caught. To remove this bare except we will need to catch sub-errors further down the call stack.
  • Line 973, bare except. Same reason as the previous bare except. This currently handles even more possible errors than on line 231. Errors will need to be handled elsewhere in Crafty before this can be resolved.

How to set up and validate locally

Test the following:

  • Creation of tasks
  • Editing of tasks
  • Scheduling of tasks
  • Execution of scheduled tasks
  • Cron task parsing
  • Deletion of temporary files
  • Deletion of files in import directory
  • Update of Gravatar PFP
  • Crafty correctly checks for new updates to Crafty

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

  • Have you checked this doesn't interfere/conflict/duplicate someone elses work?
  • Have you fully tested your changes?
  • Have you resolved any lint issues?
  • Have you assigned a reviewer?
  • Have you applied correct labels?
Edited by Wout Bouckaert

Merge request reports

Loading