forked from inventree/InvenTree
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add basic task for generating apidocs * Fix SPECTACTULAR_SETTINGS - Some provided options were not correct * Update .gitignore * Fix for duplicated API path - `/api/plugins/activate` routed to PluginActivate view - Must be associated with a specific plugin ID * By default, fail if warnings are raised * Use GenericAPIView for GetAuthToken * Use GenericAPIView for RolesDetail endpoint * Refactor more endpoints to use GenericApiView * More API cleanup * Add extra type hints for exposed methods * Update RoleDetails endpoint - Specify serializer - Use RetrieveAPI class type * More type hints * Export API docs as part of CI * add more api views docs * even more docs * extend tests to api-version * simplify serializer * and more docs * fix serializer * added more API docs * clean diff * Added APISearch base * Mention the API version bump in CONTRIBUTION.md (inventree#6436) * Mention the API version bump in CONTRIBUTION.md * Update CONTRIBUTING.md --------- Co-authored-by: Oliver <oliver.henry.walters@gmail.com> * do not assume you know the user he might be anonymously creating the schema ;-) * set empty serializer where no input is needed * Fix for build.js (inventree#6437) - Catch potential empty build_detail attribute * Maintenance Mode Fix (inventree#6422) * Custom maintenance mode backend * Implement check and retries * Update debug formatting * Use dummy model for schema generation * fix OpenAPI docs section * Week number (inventree#6439) * Support week number for batch generation * Bug fix - hour is not minute * Update docs * only run if needed * remove schema task * Add version check * pin version * fix QC order * fix assign * refactor order * optimize compile times * fix assign * onyl use install * more fixing * use full update cycle * revert python change * use api_version * run py * why? * Fix for issue 6442 (inventree#6443) - Add null option to status field for stock adjustment - Prevent stock adjustments from setting status to OK * clean up output * only check for api version diff if api_version was not touched * add schema check again * Postgresql fix (inventree#6441) * Assume maintenance mode is *on* if database is inaccessible * Specify ash shell * Update psycopg requirements * Style fixes * style fix - backends.py * Update tasks.py (inventree#6446) * Update tasks.py - Exclude temporary settings when exporting data * Remove duplicate code * use seperate filter for API * increment api_version * Added push step --------- Co-authored-by: Oliver Walters <oliver.henry.walters@gmail.com> Co-authored-by: Miklós Márton <martonmiklosqdev@gmail.com>
- Loading branch information
1 parent
c0c4e9c
commit 14f8f12
Showing
32 changed files
with
451 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
"""Custom backend implementations.""" | ||
|
||
import logging | ||
import time | ||
|
||
from django.db.utils import IntegrityError, OperationalError, ProgrammingError | ||
|
||
from maintenance_mode.backends import AbstractStateBackend | ||
|
||
import common.models | ||
import InvenTree.helpers | ||
|
||
logger = logging.getLogger('inventree') | ||
|
||
|
||
class InvenTreeMaintenanceModeBackend(AbstractStateBackend): | ||
"""Custom backend for managing state of maintenance mode. | ||
Stores the current state of the maintenance mode in the database, | ||
using an InvenTreeSetting object. | ||
""" | ||
|
||
SETTING_KEY = '_MAINTENANCE_MODE' | ||
|
||
def get_value(self) -> bool: | ||
"""Get the current state of the maintenance mode. | ||
Returns: | ||
bool: True if maintenance mode is active, False otherwise. | ||
""" | ||
try: | ||
setting = common.models.InvenTreeSetting.objects.get(key=self.SETTING_KEY) | ||
value = InvenTree.helpers.str2bool(setting.value) | ||
except common.models.InvenTreeSetting.DoesNotExist: | ||
# Database is accessible, but setting is not available - assume False | ||
value = False | ||
except (IntegrityError, OperationalError, ProgrammingError): | ||
# Database is inaccessible - assume we are not in maintenance mode | ||
logger.warning('Failed to read maintenance mode state - assuming True') | ||
value = True | ||
|
||
logger.debug('Maintenance mode state: %s', value) | ||
|
||
return value | ||
|
||
def set_value(self, value: bool, retries: int = 5): | ||
"""Set the state of the maintenance mode.""" | ||
logger.debug('Setting maintenance mode state: %s', value) | ||
|
||
while retries > 0: | ||
try: | ||
common.models.InvenTreeSetting.set_setting(self.SETTING_KEY, value) | ||
|
||
# Read the value back to confirm | ||
if self.get_value() == value: | ||
break | ||
except (IntegrityError, OperationalError, ProgrammingError): | ||
# In the database is locked, then | ||
logger.debug( | ||
'Failed to set maintenance mode state (%s retries left)', retries | ||
) | ||
time.sleep(0.1) | ||
|
||
retries -= 1 | ||
|
||
if retries == 0: | ||
logger.warning('Failed to set maintenance mode state') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.