Skip to content

Commit

Permalink
get rid of subscribe
Browse files Browse the repository at this point in the history
  • Loading branch information
rhit-windsors committed Dec 10, 2024
1 parent 97ba680 commit cf529e1
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 115 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ import { Timestamp } from 'mongodb';
import { updateExperimentNameById } from '../../../../lib/mongodb_funcs';

export interface ExperimentListingProps {
projectinit: ExperimentData;
projectData: ExperimentData;
onCopyExperiment: (experimentId: string) => void;
onDownloadResults: (experimentId: string) => Promise<void>;
onDownloadProjectZip: (experimentId: string) => Promise<void>;
onDeleteExperiment: (experimentId: string) => void;
}


export const ExperimentListing = ({ projectinit, onCopyExperiment, onDownloadResults, onDownloadProjectZip, onDeleteExperiment }: ExperimentListingProps) => {
const [project, setProject] = useState<ExperimentData>(projectinit);
export const ExperimentListing = ({ projectData: projectData, onCopyExperiment, onDownloadResults, onDownloadProjectZip, onDeleteExperiment }: ExperimentListingProps) => {
const [project, setProject] = useState<ExperimentData>(projectData);

const [busyDownloadingResults, setBusyDownloadingResults] = useState<boolean>(false);
const [busyDownloadingZip, setBusyDownloadingZip] = useState<boolean>(false);
Expand All @@ -31,10 +31,10 @@ export const ExperimentListing = ({ projectinit, onCopyExperiment, onDownloadRes
const expectedFinishTime = experimentInProgress ? new Date(project['startedAtEpochMillis'] + expectedTimeToRun * 60000) : null;
// 60000 milliseconds in a minute // Set to null if the experiment is not in progress

const [projectName, setProjectName] = useState(projectinit.name); // New state for edited project name
const [projectName, setProjectName] = useState(projectData.name); // New state for edited project name
const [isEditing, setIsEditing] = useState(false);
const [editingCanceled, setEditingCanceled] = useState(false); // New state for tracking editing cancellation
const [originalProjectName, setOriginalProjectName] = useState(projectinit.name); // State to store the original project name
const [originalProjectName, setOriginalProjectName] = useState(projectData.name); // State to store the original project name

const [isDeleteModalOpen, setDeleteModalOpen] = useState(false);

Expand Down Expand Up @@ -65,16 +65,15 @@ export const ExperimentListing = ({ projectinit, onCopyExperiment, onDownloadRes
setProjectName(originalProjectName); // Revert to the original name
setEditingCanceled(true);
} else {
const eventSource = new EventSource(`/api/experiments/subscribe?expId=${project.expId}`);
eventSource.onmessage = (event) => {
if (event.data !== 'heartbeat' && event.data) {
setProject(JSON.parse(event.data) as ExperimentData);
}

}
// Do nothing here?
}
}, [editingCanceled, originalProjectName, project.expId]);

//Update the project when data is changed
useEffect(() => {
setProject(projectData);
}, [projectData]);


const handleKeyUp = (e) => {
if (e.key === 'Enter') {
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/app/dashboard/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,7 @@ const ExperimentList = ({ experiments, onCopyExperiment, onDeleteExperiment }: E
className='relative pl-4 pr-6 py-5 hover:bg-gray-50 sm:py-6 sm:pl-6 lg:pl-8 xl:pl-6'
>
<ExperimentListing
projectinit={project}
projectData={project}
onCopyExperiment={onCopyExperiment}
onDownloadResults={downloadExperimentResults}
onDownloadProjectZip={downloadExperimentProjectZip}
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/pages/api/experiments/listen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export default async function handler(req, res) {
}
}
];
const options = {};
const options = { fullDocument: "updateLookup" };
const changeStream = experimentsCollection.watch(pipeline, options);

// Set up real-time streaming of changes to the client using SSE
Expand Down
94 changes: 0 additions & 94 deletions apps/frontend/pages/api/experiments/subscribe.tsx

This file was deleted.

18 changes: 11 additions & 7 deletions development_scripts/local/setup_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,7 @@ def setup(args):

print("Setting up kubernetes")

os.system("python3 kubernetes_init\\init.py")

# try to delete the old service
# do this so that the old minikube service dies
os.system("kubectl delete svc glados-frontend")

os.system("kubectl expose deployment glados-frontend --type LoadBalancer --port 80 --target-port 3000")
os.system("python3 kubernetes_init\\init.py --hard")

# in a new thread we need to run the following command
# minikube service glados-frontend --url
Expand All @@ -70,6 +64,7 @@ def setup(args):
def run_minikube_service():
process = subprocess.Popen(["minikube", "service", "glados-frontend", "--url"], stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
for line in process.stdout: # type: ignore
print(line)
url = line.strip()
port = url.split(":")[-1]

Expand Down Expand Up @@ -111,6 +106,15 @@ def run_minikube_service():
print(f"Frontend is now running at: http://localhost:{port}")

break
if "skip" in args:
print("Skipping redeploy")
print("Frontend is available where it was before...")
return

# try to delete the old service
# do this so that the old minikube service dies
os.system("kubectl delete svc glados-frontend")
os.system("kubectl expose deployment glados-frontend --type LoadBalancer --port 80 --target-port 3000")

thread = threading.Thread(target=run_minikube_service)
thread.start()
Expand Down

0 comments on commit cf529e1

Please sign in to comment.