From 6c529a690898a49fc58cbe680c8aa2c680c3d9c1 Mon Sep 17 00:00:00 2001 From: Donald Zou Date: Wed, 19 Jun 2024 17:09:58 +0800 Subject: [PATCH] Fixed Gunicorn issue, continue on Peer Schedule Job --- src/dashboard.py | 45 +++++----- src/gunicorn.conf.py | 4 +- .../configurationComponents/peerJobs.vue | 37 ++++---- .../scheduleDropdown.vue | 10 ++- .../schedulePeerJob.vue | 88 ++++++++++++++++--- src/wgd.sh | 5 +- 6 files changed, 127 insertions(+), 62 deletions(-) diff --git a/src/dashboard.py b/src/dashboard.py index 53f268b..df62fa5 100644 --- a/src/dashboard.py +++ b/src/dashboard.py @@ -1546,29 +1546,30 @@ def gunicornConfig(): return app_ip, app_port -def runGunicorn(): - sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False) - sqldb.row_factory = sqlite3.Row - cursor = sqldb.cursor() - _, app_ip = DashboardConfig.GetConfig("Server", "app_ip") - _, app_port = DashboardConfig.GetConfig("Server", "app_port") - WireguardConfigurations = _getConfigurationList() - bgThread = threading.Thread(target=backGroundThread) - bgThread.daemon = True - bgThread.start() - return app +# def runGunicorn(): +# sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False) +# sqldb.row_factory = sqlite3.Row +# cursor = sqldb.cursor() +# _, app_ip = DashboardConfig.GetConfig("Server", "app_ip") +# _, app_port = DashboardConfig.GetConfig("Server", "app_port") +# WireguardConfigurations = _getConfigurationList() +# bgThread = threading.Thread(target=backGroundThread) +# bgThread.daemon = True +# bgThread.start() +# return app +sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False) +sqldb.row_factory = sqlite3.Row +cursor = sqldb.cursor() +_, app_ip = DashboardConfig.GetConfig("Server", "app_ip") +_, app_port = DashboardConfig.GetConfig("Server", "app_port") +_, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path") +WireguardConfigurations = _getConfigurationList() +bgThread = threading.Thread(target=backGroundThread) +bgThread.daemon = True +bgThread.start() + if __name__ == "__main__": - sqldb = sqlite3.connect(os.path.join(CONFIGURATION_PATH, 'db', 'wgdashboard.db'), check_same_thread=False) - sqldb.row_factory = sqlite3.Row - cursor = sqldb.cursor() - _, app_ip = DashboardConfig.GetConfig("Server", "app_ip") - _, app_port = DashboardConfig.GetConfig("Server", "app_port") - _, WG_CONF_PATH = DashboardConfig.GetConfig("Server", "wg_conf_path") - WireguardConfigurations = _getConfigurationList() - bgThread = threading.Thread(target=backGroundThread) - bgThread.daemon = True - bgThread.start() - app.run(host=app_ip, debug=True, port=app_port) + diff --git a/src/gunicorn.conf.py b/src/gunicorn.conf.py index 5f18f8e..a627725 100644 --- a/src/gunicorn.conf.py +++ b/src/gunicorn.conf.py @@ -4,8 +4,8 @@ import dashboard app_host, app_port = dashboard.gunicornConfig() worker_class = 'gthread' -workers = multiprocessing.cpu_count() * 2 + 1 +workers = 4 threads = 2 bind = f"{app_host}:{app_port}" daemon = True -pidfile = './gunicorn.pid' +pidfile = './gunicorn.pid' \ No newline at end of file diff --git a/src/static/app/src/components/configurationComponents/peerJobs.vue b/src/static/app/src/components/configurationComponents/peerJobs.vue index 0d9d003..812fef7 100644 --- a/src/static/app/src/components/configurationComponents/peerJobs.vue +++ b/src/static/app/src/components/configurationComponents/peerJobs.vue @@ -16,19 +16,26 @@ export default { Field: [ { display: "Total Received", - value: "total_receive" + value: "total_receive", + unit: "GB", + type: 'number' }, { display: "Total Sent", - value: "total_sent" + value: "total_sent", + unit: "GB", + type: 'number' }, { display: "Total Data", - value: "total_data" + value: "total_data", + unit: "GB", + type: 'number' }, { display: "Date", - value: "date" + value: "date", + type: 'date' } ], Operator: [ @@ -62,8 +69,7 @@ export default { }, } - }, - + } } @@ -78,22 +84,15 @@ export default {
-
- - Name - - {{selectedPeer.name ? selectedPeer.name : "Untitled Peer"}} -
-
- - Public Key - - {{this.selectedPeer.id}} -
+ + + + + + :pjob="job" v-for="job in this.selectedPeer.jobs">
diff --git a/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue b/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue index bde9f25..3aaf99c 100644 --- a/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue +++ b/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/scheduleDropdown.vue @@ -6,6 +6,7 @@ export default { props: { options: Array, data: String, + edit: false }, mounted() { console.log(this.options) @@ -19,8 +20,8 @@ export default { \ No newline at end of file diff --git a/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue b/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue index 39cfc2f..dc4a979 100644 --- a/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue +++ b/src/static/app/src/components/configurationComponents/peerScheduleJobsComponents/schedulePeerJob.vue @@ -6,8 +6,44 @@ export default { components: {ScheduleDropdown}, props: { dropdowns: Array[Object], - job: Object - } + pjob: Object + }, + data(){ + return { + job: Object, + inputType: undefined, + edit: false + } + }, + beforeMount() { + this.job = JSON.parse(JSON.stringify(this.pjob)) + }, + methods: { + save(){ + if (this.job.Field && this.job.Operator && this.job.Action && this.job.Value){ + if (this.job.Field === 'date'){ + this.job.Value = new Date(this.job.Value).getTime(); + } + }else{ + this.alert(); + } + }, + alert(){ + let animation = "animate__flash"; + let dropdowns = this.$el.querySelectorAll(".scheduleDropdown"); + let inputs = this.$el.querySelectorAll("input"); + dropdowns.forEach(x => x.classList.add("animate__animated", animation)) + inputs.forEach(x => x.classList.add("animate__animated", animation)) + setTimeout(() => { + dropdowns.forEach(x => x.classList.remove("animate__animated", animation)) + inputs.forEach(x => x.classList.remove("animate__animated", animation)) + }, 2000) + }, + reset(){ + this.job = JSON.parse(JSON.stringify(this.pjob)); + this.edit = false; + } + }, } @@ -16,47 +52,71 @@ export default {
Job ID - {{this.job.JobID}} + {{this.job.JobID}}
-
+
if is - + + - { + {{this.dropdowns.Field.find(x => x.value === this.job.Field).unit}} {
- - execute - + execute - - ; - + ;
-
+
diff --git a/src/wgd.sh b/src/wgd.sh index fcfee55..db53127 100755 --- a/src/wgd.sh +++ b/src/wgd.sh @@ -1,6 +1,6 @@ #!/bin/bash -# wgd.sh - Copyright(C) 2021 Donald Zou [https://github.com/donaldzou] +# wgd.sh - Copyright(C) 2024 Donald Zou [https://github.com/donaldzou] # Under Apache-2.0 License app_name="dashboard.py" app_official_name="WGDashboard" @@ -102,7 +102,8 @@ gunicorn_start () { export PATH=$PATH:/usr/local/bin:$HOME/.local/bin fi gunicorn --access-logfile log/access_"$d".log \ - --error-logfile log/error_"$d".log 'dashboard:runGunicorn()' + --log-level 'debug' --capture-output \ + --error-logfile log/error_"$d".log 'dashboard:app' printf "| Log files is under log/ |\n" printf "%s\n" "$dashes" }