Skip to content

Commit 6a98c67

Browse files
committed
Updated loading alert
1 parent c7517fe commit 6a98c67

File tree

3 files changed

+20
-10
lines changed
  • src
    • aws/functions/start_instance
    • dashboard/frontend/traffic-conflicts-analysis/src

3 files changed

+20
-10
lines changed

src/aws/functions/start_instance/main.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ def lambda_handler(event, context):
4343

4444
print("Services in EC2 are running")
4545

46-
time.sleep(10)
46+
# Wait for 25 seconds before calling the BEV service
47+
time.sleep(50)
4748

4849
# Check if the API has default matrix
4950
response = requests.get(DEFAULT_MATRIX_URL + "?id=" + video_id)

src/dashboard/frontend/traffic-conflicts-analysis/src/app/dashboard/inicio/page.tsx

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,14 @@ export default function Home() {
2222

2323
const [duration, setDuration] = useState(-1);
2424
const [progress, setProgress] = useState(0);
25+
const [videoProcessProgress, setVideoProcessProgress] = useState(0);
2526

2627
const { data: lastFile } = api.video.getLastVideo.useQuery();
2728

29+
if (lastFile && lastFile.progress !== videoProcessProgress) {
30+
setVideoProcessProgress(lastFile.progress);
31+
}
32+
2833
const { data: isInstanceStopped, isLoading } =
2934
api.aws.isInstanceStopped.useQuery();
3035

@@ -60,7 +65,8 @@ export default function Home() {
6065
}
6166
},
6267
});
63-
alert("El archivo se subió correctamente.");
68+
setVideoProcessProgress(5);
69+
alert("El archivo se subió correctamente. Y se está procesando.");
6470
} catch (error) {
6571
console.error("Error uploading file:", error);
6672
alert("Hubo un error al subir el archivo.");
@@ -192,11 +198,16 @@ export default function Home() {
192198

193199
<button
194200
disabled={
195-
isLoading || !isInstanceStopped || sizeMB > SIZE_LIMIT_MB || progress !== 0
201+
isLoading ||
202+
!isInstanceStopped ||
203+
sizeMB > SIZE_LIMIT_MB ||
204+
progress !== 0
196205
}
197206
className={twMerge(
198207
"rounded-lg bg-gray-400 p-2 px-12 py-3 text-center text-sm font-bold text-white md:p-3 md:text-2xl",
199-
isInstanceStopped && (sizeMB <= SIZE_LIMIT_MB)? "bg-verde" : "",
208+
isInstanceStopped && sizeMB <= SIZE_LIMIT_MB
209+
? "bg-verde"
210+
: "",
200211
)}
201212
onClick={async () => {
202213
if (
@@ -275,8 +286,8 @@ export default function Home() {
275286
backgroundColor: "#00A94F",
276287
pathColor: "#00A94F",
277288
})}
278-
value={lastFile?.progress ?? 0}
279-
text={`${lastFile?.progress ?? 0}%`}
289+
value={videoProcessProgress}
290+
text={`${videoProcessProgress}%`}
280291
/>
281292
<button
282293
disabled={!lastFile || lastFile?.progress !== 100}

src/dashboard/frontend/traffic-conflicts-analysis/src/server/api/routers/video.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { TRPCError } from "@trpc/server";
12
import { z } from "zod";
23

34
import {
@@ -44,9 +45,6 @@ export const videoRouter = createTRPCRouter({
4445
.mutation(async ({ ctx, input }) => {
4546

4647
const lastVideo = await ctx.db.video.findFirst({
47-
where: {
48-
userId: ctx.session.user.id,
49-
},
5048
orderBy: {
5149
createdAt: "desc",
5250
},
@@ -55,7 +53,7 @@ export const videoRouter = createTRPCRouter({
5553
const currentTime = new Date().getTime();
5654

5755
if (lastVideo && currentTime - lastVideo.createdAt.getTime() < 1000 * 60 * 5) {
58-
throw new Error("Tienes que esperar por lo menos 5 minutos para subir otro video");
56+
throw new TRPCError({ code: "TOO_MANY_REQUESTS", message: "Algún usuario subió un video en los últimos 5 minutos" });;
5957
}
6058

6159
const video = await ctx.db.video.create({

0 commit comments

Comments
 (0)