diff --git a/server/Dockerfile b/server/Dockerfile deleted file mode 100644 index 00310418..00000000 --- a/server/Dockerfile +++ /dev/null @@ -1,51 +0,0 @@ -FROM --platform=$BUILDPLATFORM mcr.microsoft.com/playwright:v1.46.0-noble - -# Set working directory -WORKDIR /app - -# Install node dependencies -COPY package*.json ./ -COPY src ./src -COPY public ./public -COPY server ./server -COPY tsconfig.json ./ -COPY server/tsconfig.json ./server/ -# COPY server/start.sh ./ - -# Install dependencies -RUN npm install --legacy-peer-deps - -# Install Playwright browsers and dependencies -RUN npx playwright install --with-deps chromium - -# Create the Chromium data directory with necessary permissions -RUN mkdir -p /tmp/chromium-data-dir && \ - chmod -R 777 /tmp/chromium-data-dir - -# Install dependencies -RUN apt-get update && apt-get install -y \ - libgbm1 \ - libnss3 \ - libatk1.0-0 \ - libatk-bridge2.0-0 \ - libdrm2 \ - libxkbcommon0 \ - libglib2.0-0 \ - libdbus-1-3 \ - libx11-xcb1 \ - libxcb1 \ - libxcomposite1 \ - libxcursor1 \ - libxdamage1 \ - libxext6 \ - libxi6 \ - libxtst6 \ - && rm -rf /var/lib/apt/lists/* \ - && mkdir -p /tmp/.X11-unix && chmod 1777 /tmp/.X11-unix - -# Expose backend port -EXPOSE ${BACKEND_PORT:-8080} - -# Run migrations & start backend using start script -#CMD ["npm", "run", "server"] -CMD ["sh", "-c", "npm run migrate && npm run server"] \ No newline at end of file diff --git a/server/src/routes/storage.ts b/server/src/routes/storage.ts index b4e8cdfd..ee37b2be 100644 --- a/server/src/routes/storage.ts +++ b/server/src/routes/storage.ts @@ -889,33 +889,59 @@ router.delete('/schedule/:id', requireSignIn, async (req: AuthenticatedRequest, */ router.post('/runs/abort/:id', requireSignIn, async (req: AuthenticatedRequest, res) => { try { - if (!req.user) { return res.status(401).send({ error: 'Unauthorized' }); } - - const run = await Run.findOne({ where: { - runId: req.params.id, - runByUserId: req.user.id, - } }); - - if (!run) { - return res.status(404).send(false); + if (!req.user) { + return res.status(401).send({ error: 'Unauthorized' }); } - - const userQueueName = `abort-run-user-${req.user.id}`; - await pgBoss.createQueue(userQueueName); - - await pgBoss.send(userQueueName, { - userId: req.user.id, - runId: req.params.id + + const run = await Run.findOne({ + where: { + runId: req.params.id, + runByUserId: req.user.id, + } }); - + + if (!run) { + return res.status(404).send({ error: 'Run not found' }); + } + + if (!['running', 'queued'].includes(run.status)) { + return res.status(400).send({ + error: `Cannot abort run with status: ${run.status}` + }); + } + await run.update({ status: 'aborting' }); + + if (run.status === 'queued') { + await run.update({ + status: 'aborted', + finishedAt: new Date().toLocaleString(), + log: 'Run aborted while queued' + }); + + return res.send({ success: true, message: 'Queued run aborted' }); + } + + const userQueueName = `abort-run-user-${req.user.id}`; + await pgBoss.createQueue(userQueueName); - return res.send(true); + const jobId = await pgBoss.send(userQueueName, { + userId: req.user.id, + runId: req.params.id + }); + + logger.log('info', `Abort signal sent for run ${req.params.id}, job ID: ${jobId}`); + + return res.send({ + success: true, + message: 'Abort signal sent', + jobId + }); + } catch (e) { const { message } = e as Error; - logger.log('info', `Error while aborting run with id: ${req.params.id} - ${message}`); - return res.send(false); + logger.log('error', `Error aborting run ${req.params.id}: ${message}`); + return res.status(500).send({ error: 'Failed to abort run' }); } -});