Run task on worker creation
Is it possible to make a serverless worker run a custom script on the first startup before its considered "ready"?
29 Replies
"ready" = "idle"?
you can run scripts either when its "running" or when you're building the docker image
it cant be when the docker image is built because its specific to the machine
before it goes to that state
no
specific to the machine? i thought runpod only uses linux
i mean the gpu
its some optimizations
No, but you can either run it before on building or after while running
doesnt make sense to put it in the docker image since itll be slightly different for each card
i try to do it while running but it ends up just forwarding the request to the already initialized worker
forwarding request?
then after works well while running but before you execute anything else
thats what i am currently doing
but the problem is say I require 10 workers
9 of them are initialized already
How do you do that? im not clear yet, why do requests i thought it just run some commands / configs to the serverless worker on runpod
but one of them isnt
and it takes a minute to
im wasting 9 minutes of exeuction time waiting for the one worker that hasnt executed
i make the worker open a websocket connection to my server where it then gets the workload from
Oh like all of them is an active worker?
no none of them are active worker
well ok, im not sure yet what scripts or what things you do for those 9 minutes for getting it "initialized" can you explain more
so it takes a minute to run the initialization part
currently what im doing is im getting a worker by sending a /run to the serverless endpoint, with a connection endpoint to my server
when the worker starts up, it checks if its ready or not and runs the script as neccessary
when its done it tells my server its ready
This pattern seems unconventional for runpod serverless
yea, i have it that way because i noticed running it through the runpod endpoint is a bit unstable sometimes
oh
unstable like what?
okay then, whats the problem right now that you're asking
this issue
https://discord.com/channels/912829806415085598/1261380977544921159
i want to be able to have my worker run a custom script before it is considered ready for requests
yeah you can like after its running
how?
i want it to run right after the container is started
from your dockerfile, there's an CMD or ENTRYPOINT correct?
yes
where does it point to?
it starts the worker to receive requests
yup so, before that you can point that cmd or entrypoint to a sh file
i will give that a try
You can do this:
yeah that too
this works great, thanks!