https://prefect.io logo
n

Nic

12/19/2022, 10:45 AM
Has anybody had success with running prefect agent locally as a background process on a windows machine like you can do with supervisor on a linux system? I've found this thread https://discourse.prefect.io/t/how-to-run-your-prefect-agent-as-a-background-process-with-supervisord/1551. but seems like supervisor-win might be broken currently. How else could i go about this?
βœ… 1
a

Anna Geller

12/19/2022, 1:53 PM
let me tag @Ryan Peden, he will know that best (he may even have already written a Discourse topic about it and I just don't remember which one is it πŸ˜…)
r

Ryan Peden

12/19/2022, 1:54 PM
I don't think I have written one yet, but I could! You can wrap the agent in a Windows service using pure Python, but the quickest and easiest way is using NSSM.
gratitude thank you 2
πŸ™Œ 3
n

Nic

12/19/2022, 1:55 PM
@Ryan Peden would absolutely love a topic on it - seems like it could be helpful for other people that might be using windows for one reason or another πŸ™‚
If i run script as a service through NSSM, and... Let's say the agent doesn't shutdown but reach some unstable network or other similar issues. Would NSSM be able to catch this and customize the action to try restarting the agent?
r

Ryan Peden

12/19/2022, 1:59 PM
I don't think so, but I'm not sure that any of the other options on Windows would either. However if the agent can't connect to the server properly after a certain number of retries, I believe it will shut itself down anyway, at which point NSSM would restart it.
πŸ‘ 1
n

Nic

12/19/2022, 2:01 PM
Great, i will try it out πŸ™‚
a

Anna Geller

12/19/2022, 2:08 PM
lol that name NSSM - is it even true? πŸ˜‚
πŸ˜† 1
r

Ryan Peden

12/19/2022, 2:22 PM
The name is true, but the name is also what causes the most resistance when I recommend NSSM. I sort of want to make my own open source app called PWSM (Professional Windows Server Manager) and capture the market of people who want an app that does what NSSM does but don't use it because of its name πŸ˜†
πŸ’― 1
😁 2
c

Christopher Boyd

12/19/2022, 7:01 PM
I set this up as a scheduled service, it’s been a hot minute and probably like early 2.x but I can find the example
πŸ‘ 1
start_agent.bat:
Copy code
@ECHO OFF
C:\Users\christopherboyd\AppData\Local\Programs\Python\Python39\Scripts\prefect.exe agent start default
PAUSE

# Task Scheduler
# Task Scheduler
Create new Basic Task
Name it "prefect agent"
Select "When the computer starts"
Select "Start a program"
Browser -> Select Batch script
Finish
πŸ‘ 2
4 Views