revoke verifiy id function
Browse files
app.py
CHANGED
|
@@ -8,18 +8,8 @@ import secrets
|
|
| 8 |
from DB_utils import find_unused_wells, update_used_wells, save_result, get_student_quota, decrement_student_quota
|
| 9 |
import os
|
| 10 |
from yt_utils import get_latest_video_id
|
| 11 |
-
from prefect import
|
| 12 |
from prefect_utils import start_prefect_worker
|
| 13 |
-
from prefect import get_run_logger, settings
|
| 14 |
-
from prefect.blocks.notifications import SlackWebhook
|
| 15 |
-
from prefect.context import get_run_context
|
| 16 |
-
from prefect.input import RunInput
|
| 17 |
-
|
| 18 |
-
class VerificationInput(RunInput):
|
| 19 |
-
approved: bool
|
| 20 |
-
comments: str = ""
|
| 21 |
-
|
| 22 |
-
|
| 23 |
|
| 24 |
# NOTE: New global dict to store tasks keyed by (student_id, experiment_id)
|
| 25 |
tasks_dict = {}
|
|
@@ -30,8 +20,6 @@ current_task = None
|
|
| 30 |
sensor_results = None
|
| 31 |
queue_counter = task_queue.qsize()
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
MQTT_BROKER = os.getenv("MQTT_BROKER")
|
| 36 |
MQTT_PORT = int(os.getenv("MQTT_PORT"))
|
| 37 |
MQTT_USERNAME = os.getenv("MQTT_USERNAME")
|
|
@@ -232,32 +220,16 @@ def verify_student_id(student_id):
|
|
| 232 |
|
| 233 |
quota_remaining = check_student_quota(student_id)
|
| 234 |
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
logger.info(f"Student ID: {student_id} requested verification. Quota remaining: {quota_remaining}")
|
| 238 |
-
|
| 239 |
-
if flow_run and settings.PREFECT_UI_URL:
|
| 240 |
-
flow_run_url = f"{settings.PREFECT_UI_URL.value()}/flow-runs/flow-run/{flow_run.id}"
|
| 241 |
-
logger.info(f"Please review and resume the flow here: {flow_run_url}")
|
| 242 |
-
|
| 243 |
-
user_input = pause_flow_run(
|
| 244 |
-
wait_for_input=VerificationInput.with_initial_data(
|
| 245 |
-
description="Approve this Student ID to continue the experiment?",
|
| 246 |
-
approved=False,
|
| 247 |
-
comments="",
|
| 248 |
-
),
|
| 249 |
-
timeout=300, # 10 minutes
|
| 250 |
-
)
|
| 251 |
-
|
| 252 |
-
if not user_input.approved:
|
| 253 |
return [
|
| 254 |
gr.update(interactive=False, value=0),
|
| 255 |
gr.update(interactive=False, value=0),
|
| 256 |
gr.update(interactive=False, value=0),
|
| 257 |
-
"
|
| 258 |
gr.update(interactive=False)
|
| 259 |
]
|
| 260 |
-
|
| 261 |
return [
|
| 262 |
gr.update(interactive=True, value=0),
|
| 263 |
gr.update(interactive=True, value=0),
|
|
@@ -265,7 +237,6 @@ def verify_student_id(student_id):
|
|
| 265 |
f"Student ID verified. Available experiments: {quota_remaining}\nCurrent queue length: {queue_counter} experiment(s)",
|
| 266 |
gr.update(interactive=True)
|
| 267 |
]
|
| 268 |
-
|
| 269 |
def update_status_with_queue(R, Y, B):
|
| 270 |
"""Check if RYB inputs are valid and return updated queue info"""
|
| 271 |
global queue_counter
|
|
|
|
| 8 |
from DB_utils import find_unused_wells, update_used_wells, save_result, get_student_quota, decrement_student_quota
|
| 9 |
import os
|
| 10 |
from yt_utils import get_latest_video_id
|
| 11 |
+
from prefect import flow
|
| 12 |
from prefect_utils import start_prefect_worker
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
|
| 14 |
# NOTE: New global dict to store tasks keyed by (student_id, experiment_id)
|
| 15 |
tasks_dict = {}
|
|
|
|
| 20 |
sensor_results = None
|
| 21 |
queue_counter = task_queue.qsize()
|
| 22 |
|
|
|
|
|
|
|
| 23 |
MQTT_BROKER = os.getenv("MQTT_BROKER")
|
| 24 |
MQTT_PORT = int(os.getenv("MQTT_PORT"))
|
| 25 |
MQTT_USERNAME = os.getenv("MQTT_USERNAME")
|
|
|
|
| 220 |
|
| 221 |
quota_remaining = check_student_quota(student_id)
|
| 222 |
|
| 223 |
+
|
| 224 |
+
if quota_remaining <= 0:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
return [
|
| 226 |
gr.update(interactive=False, value=0),
|
| 227 |
gr.update(interactive=False, value=0),
|
| 228 |
gr.update(interactive=False, value=0),
|
| 229 |
+
"No experiments remaining. Please contact administrator.",
|
| 230 |
gr.update(interactive=False)
|
| 231 |
]
|
| 232 |
+
|
| 233 |
return [
|
| 234 |
gr.update(interactive=True, value=0),
|
| 235 |
gr.update(interactive=True, value=0),
|
|
|
|
| 237 |
f"Student ID verified. Available experiments: {quota_remaining}\nCurrent queue length: {queue_counter} experiment(s)",
|
| 238 |
gr.update(interactive=True)
|
| 239 |
]
|
|
|
|
| 240 |
def update_status_with_queue(R, Y, B):
|
| 241 |
"""Check if RYB inputs are valid and return updated queue info"""
|
| 242 |
global queue_counter
|