kristiankauffeld
kristiankauffeld
Explore posts from servers
RRailway
Created by kristiankauffeld on 5/4/2024 in #✋|help
help with memory profiling FastAPI application
No description
16 replies
RRailway
Created by kristiankauffeld on 2/10/2024 in #✋|help
best practices for deploying FastAPI, Redis and RQ workers?
I have deployed a FastAPI server and a RQ Worker in separate containers on Railway based on the same monorepo: https://github.com/kristiankauffeld/fastapi-redis The repo is structured by separating the services into different directories where they have their own Dockerfile. The two services communicate through a Redis instance. Currently there is some code duplication since I have copied the "utils" folder both into the "api" and the "rq-worker" folder. So if anyone perhaps could share some insight whether there is a better approach to deploy an application like this. Thanks
33 replies
RRailway
Created by kristiankauffeld on 1/14/2024 in #✋|help
how to deploy a CPU-only version of PyTorch
I am trying to deploy a FastAPI application in a Docker container and I think I need to deploy a CPU-only version since as I understand Railway doesn't support GPU yet. Do anyone in here know how to deploy a CPU-only version of PyTorch and related libraries, including torchaudio? I have seen that the Demucs repo has an "environment-cpu.yml" file: https://github.com/facebookresearch/demucs/blob/main/environment-cpu.yml
10 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/27/2023 in #workers-help
Fetch Request Returns 'Undefined' during File Upload Polling Process"
I am experiencing an issue with my Cloudflare Worker that is part of a file upload process using the UploadThing library. The worker is responsible for polling the upload status from an external server (https://uploadthing.com/api/pollUpload/...). However, I'm encountering a problem where the polling doesn't happen and the fetch request within the worker therefore does not return a response, resulting in an 'undefined' value. Below is a summary of the process and where the issue occurs: 1. A POST request is initiated to http://localhost:3000/api/uploadthing?actionType=upload&slug=videoAndImage. 2. This triggers the buildRequestHandler function within UploadThing, which parses the request and forwards it to https://uploadthing.com/api/prepareUpload. 3. Upon receiving a successful response from UploadThing, the conditionalDevServer function called in buildRequestHandler initiates a polling process using pollForFileData. 4. pollForFileData, wrapped with withExponentialBackoff, makes a fetch request to https://uploadthing.com/api/pollUpload/... to check the upload status. 5. The fetch request is configured with the necessary headers, including an API key and SDK version. 6. However, the polling doesn't happen, and the fetch request does not return any response, resulting in 'undefined'. I have attached a video demonstrating the issue, where I step through the execution using a debugger. Additionally, here is the link to a pull request (PR) that is currently being worked on in the UploadThing repository: https://github.com/pingdotgg/uploadthing/pull/514/commits This PR contains relevant code changes that might provide further insights into the issue. I am looking for insights into why the polling doesn't return a response. Any suggestions on troubleshooting steps, potential causes, or configuration changes that could resolve this issue would be greatly appreciated. Thank you in advance for your help
2 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/19/2023 in #workers-help
Your worker created multiple branches of a single stream (for instance, by calling response.clone()
I am getting this when trying to use a cloudflare worker together with the uploadthing library. I have debugged in VS-code and the error is thrown here when uploadthing library calls the safeParseJSON function: https://github.com/pingdotgg/uploadthing/blob/ea0f3c96f5db2fa945592d5efc06bf84811c5525/packages/shared/src/utils.ts#L233 Here is link to my cloudflare worker: https://github.com/kristiankauffeld/uploadthing-cf-worker
5 replies
CDCloudflare Developers
Created by kristiankauffeld on 12/7/2023 in #workers-help
ReferenceError process is not defined
I am trying to use UploadThing together with a Cloudflare Worker and tiny-request-router. Currently when I send a POST request with a png file attached via Insomnia to my "api/uploadthing" endpoint, I receive the following error "ReferenceError process is not defined". Here is what my "index.ts file looks like:
import { Env, Handler } from './types';
import { Method, Router } from 'tiny-request-router';
import { uploadRouter } from './uploadthing';
import { createServerHandler } from 'uploadthing/server';
import * as process from 'node:process';

const { GET, POST } = createServerHandler({
router: uploadRouter,
});

const router = new Router<Handler>();

router.post('/api/uploadthing', async (req, env) => POST(req));
router.get('/api/uploadthing', async (req) => GET(req));

const worker: ExportedHandler<Env> = {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
process.env.UPLOADTHING_SECRET ??= env.UPLOADTHING_SECRET;
process.env.UPLOADTHING_APP_ID ??= env.UPLOADTHING_APP_ID;

const url = new URL(request.url);
const match = router.match(request.method as Method, url.pathname);

if (!match) return new Response('Not found', { status: 404 });

return match.handler(request, env);
},
};

export default worker;
import { Env, Handler } from './types';
import { Method, Router } from 'tiny-request-router';
import { uploadRouter } from './uploadthing';
import { createServerHandler } from 'uploadthing/server';
import * as process from 'node:process';

const { GET, POST } = createServerHandler({
router: uploadRouter,
});

const router = new Router<Handler>();

router.post('/api/uploadthing', async (req, env) => POST(req));
router.get('/api/uploadthing', async (req) => GET(req));

const worker: ExportedHandler<Env> = {
async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
process.env.UPLOADTHING_SECRET ??= env.UPLOADTHING_SECRET;
process.env.UPLOADTHING_APP_ID ??= env.UPLOADTHING_APP_ID;

const url = new URL(request.url);
const match = router.match(request.method as Method, url.pathname);

if (!match) return new Response('Not found', { status: 404 });

return match.handler(request, env);
},
};

export default worker;
Here is what my "wrangler.toml" file looks like:
name = "backend"
main = "src/index.ts"
compatibility_date = "2023-11-21"
compatibility_flags = [ "nodejs_compat" ]


[vars]
API_HOST = "example.com"
API_ACCOUNT_ID = "example_user"
SERVICE_X_DATA = { URL = "service-x-api.dev.example", MY_ID = 123 }
name = "backend"
main = "src/index.ts"
compatibility_date = "2023-11-21"
compatibility_flags = [ "nodejs_compat" ]


[vars]
API_HOST = "example.com"
API_ACCOUNT_ID = "example_user"
SERVICE_X_DATA = { URL = "service-x-api.dev.example", MY_ID = 123 }
And this is my "types.ts" file:
export interface Env {
UPLOADTHING_SECRET: string;
UPLOADTHING_APP_ID: string;
}

export type Handler = (request: Request, env: Env) => Response | Promise<Response>;
export interface Env {
UPLOADTHING_SECRET: string;
UPLOADTHING_APP_ID: string;
}

export type Handler = (request: Request, env: Env) => Response | Promise<Response>;
10 replies