14
.vscode/launch.json
vendored
14
.vscode/launch.json
vendored
@ -4,6 +4,7 @@
|
||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
|
||||
{
|
||||
"name": "Centurion",
|
||||
"type": "debugpy",
|
||||
@ -40,6 +41,19 @@
|
||||
"PROMETHEUS_MULTIPROC_DIR": ""
|
||||
}
|
||||
},
|
||||
{
|
||||
"name": "Centurion Feature Flag (Management Command)",
|
||||
"type": "debugpy",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"feature_flag",
|
||||
// "0.0.0.0:8002"
|
||||
],
|
||||
"django": true,
|
||||
"autoStartBrowser": false,
|
||||
"program": "${workspaceFolder}/app/manage.py"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "Migrate",
|
||||
"type": "debugpy",
|
||||
|
@ -0,0 +1,70 @@
|
||||
import subprocess
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
||||
from app import settings
|
||||
|
||||
from centurion_feature_flag.lib.feature_flag import CenturionFeatureFlagging
|
||||
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = 'Running this command will download the available feature flags form the Centurion Server if the cache has expired (>4hours) or the cache file does not exist.'
|
||||
|
||||
|
||||
def add_arguments(self, parser):
|
||||
parser.add_argument('-r', '--reload', action='store_true', help='Restart the Centurion Process')
|
||||
|
||||
|
||||
def handle(self, *args, **kwargs):
|
||||
|
||||
if getattr(settings,'feature_flag', None):
|
||||
|
||||
feature_flagging = CenturionFeatureFlagging(
|
||||
url = settings.feature_flag['url'],
|
||||
user_agent = settings.feature_flag['user_agent'],
|
||||
cache_dir = settings.feature_flag['cache_dir']
|
||||
)
|
||||
|
||||
self.stdout.write('Fetching Feature Flags.....')
|
||||
|
||||
feature_flagging.get()
|
||||
|
||||
if feature_flagging:
|
||||
|
||||
self.stdout.write('Success.')
|
||||
|
||||
else:
|
||||
|
||||
self.stdout.stderr('Error. Something went wrong.')
|
||||
|
||||
if kwargs['reload']:
|
||||
|
||||
if settings.BUILD_SHA:
|
||||
|
||||
self.stdout.write('restarting Centurion')
|
||||
|
||||
restart = subprocess.run(["supervisorctl", "restart", "gunicorn"], capture_output = True)
|
||||
|
||||
status = subprocess.run(["supervisorctl", "status", "gunicorn"], capture_output = True)
|
||||
|
||||
if status.returncode == 0:
|
||||
|
||||
self.stdout.write('Centurion restarted successfully')
|
||||
|
||||
|
||||
|
||||
a = 'b'
|
||||
|
||||
else:
|
||||
|
||||
self.stdout.write('using kwarg `--reload` whilst not within production does nothing.')
|
||||
|
||||
else:
|
||||
|
||||
self.stdout.write('Feature Flaggin is not enabled')
|
||||
|
||||
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user