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
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
it cant be when the docker image is built because its specific to the machine before it goes to that state
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
i mean the gpu its some optimizations
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo 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
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
thats what i am currently doing but the problem is say I require 10 workers 9 of them are initialized already
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo 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
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
no none of them are active worker
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo 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
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
yea, i have it that way because i noticed running it through the runpod endpoint is a bit unstable sometimes
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo 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
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
how? i want it to run right after the container is started
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
yes
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
it starts the worker to receive requests
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
i will give that a try
Encyrption
Encyrption15mo 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})
Unknown User
Unknown User15mo ago
Message Not Public
Sign In & Join Server To View
1AndOnlyPika
1AndOnlyPikaOP15mo ago
this works great, thanks!

Did you find this page helpful?