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
nerdylive
nerdylive4mo ago
"ready" = "idle"? you can run scripts either when its "running" or when you're building the docker image
1AndOnlyPika
1AndOnlyPikaOP4mo ago
it cant be when the docker image is built because its specific to the machine before it goes to that state
nerdylive
nerdylive4mo ago
no specific to the machine? i thought runpod only uses linux
1AndOnlyPika
1AndOnlyPikaOP4mo ago
i mean the gpu its some optimizations
nerdylive
nerdylive4mo ago
No, but you can either run it before on building or after while running
1AndOnlyPika
1AndOnlyPikaOP4mo ago
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
nerdylive
nerdylive4mo ago
forwarding request? then after works well while running but before you execute anything else
1AndOnlyPika
1AndOnlyPikaOP4mo ago
thats what i am currently doing but the problem is say I require 10 workers 9 of them are initialized already
nerdylive
nerdylive4mo ago
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
1AndOnlyPika
1AndOnlyPikaOP4mo ago
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
nerdylive
nerdylive4mo ago
Oh like all of them is an active worker?
1AndOnlyPika
1AndOnlyPikaOP4mo ago
no none of them are active worker
nerdylive
nerdylive4mo ago
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
1AndOnlyPika
1AndOnlyPikaOP4mo ago
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
nerdylive
nerdylive4mo ago
This pattern seems unconventional for runpod serverless
1AndOnlyPika
1AndOnlyPikaOP4mo ago
yea, i have it that way because i noticed running it through the runpod endpoint is a bit unstable sometimes
nerdylive
nerdylive4mo ago
oh unstable like what? okay then, whats the problem right now that you're asking
1AndOnlyPika
1AndOnlyPikaOP4mo ago
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
nerdylive
nerdylive4mo ago
yeah you can like after its running
1AndOnlyPika
1AndOnlyPikaOP4mo ago
how? i want it to run right after the container is started
nerdylive
nerdylive4mo ago
from your dockerfile, there's an CMD or ENTRYPOINT correct?
1AndOnlyPika
1AndOnlyPikaOP4mo ago
yes
nerdylive
nerdylive4mo ago
where does it point to?
1AndOnlyPika
1AndOnlyPikaOP4mo ago
it starts the worker to receive requests
nerdylive
nerdylive4mo ago
yup so, before that you can point that cmd or entrypoint to a sh file
1AndOnlyPika
1AndOnlyPikaOP4mo ago
i will give that a try
Encyrption
Encyrption4mo ago
You can do this:
if __name__ == "__main__":
#
# Put your code here to run before the handler starts
#
runpod.serverless.start({'handler': handler})
if __name__ == "__main__":
#
# Put your code here to run before the handler starts
#
runpod.serverless.start({'handler': handler})
nerdylive
nerdylive4mo ago
yeah that too
1AndOnlyPika
1AndOnlyPikaOP4mo ago
this works great, thanks!
Want results from more Discord servers?
Add your server