Im struggling with something that im hoping someone can lead me in the right direction.
I have created an app with a schedule hook. The py script im running needs to listen on a server socket I got from my service provider that receives incoming ussd messages in xml format. I have this working but my challenge is that the service providers connection timesout after a hour and does not send any disconnect message so the socket remains open but dead so the python code now keeps running in this state.
Even if I set the schedule to ‘all’ its not stopping the script and rerunning.
What I would like to do i be able to stop the client socket and re-run or reconnect. Or maybe some guideline on how to better structure this code.
all this is all server code cause im planning to extend this app so it can interact with erpnext so my customer can use ussd messaging to get data from erpnext.
@rmetha I think the API is not important cause im trying to understand how sockets work in ERPNext. Even if we use simple sockets to test with what im trying to achieve is that when the next schedule need to run my code I need to figure out how to kill the previous running schedule so that we can reconnect and get the socket active again.
Also, if I use threads with that work, trying to study that now and I see that I can run threads as daemons as well. Im sure I can write a separate python app for what im trying to achieve and just use the erpnext rest api to access data but I wanted to have all running in erpnext if possible.
my procedure is:
On the hour start the ussd.py script
The script needs to spawn other processes depending on user input as i dont want to run long processes in ussd.py - this should only receive messages and then pass to a message process - or maybe I can use a queue or something that another py file can be listening on
Scheduler should re-run ussd.py and kill and sockets if active then re-connect.
what would happen is I run command sys.exit()? Cause if this does not stop frappe to stop then I can have 2 schedules, one will be uusd.py and the other will set a flag in the database that I can read during the “While 1:” to exit ussd.py then the scheduler will start it up on next run. I would prefer if I can immediately run it in stead of waiting for the schedule.
This what I want to achieve, just need some ideas on how I can go about trying this. Hope im clear.
I’m going to get the test server I have created for testing so that we can all work on the client code. Ive put the code I have on pastebin, but will do so again with the connection to this test server.
I have a full system running but on Windows and now I’m trying to port to erpnext.
I am getting somewhere now…I know I said I was going to create a test but I could not get the windev code to work with my python code…so scrapped that idea.
where am I now.
created a stand alone python script that almost does what I want
how do I get the frappe_client to read the settings page i created. I read another place on the forum that the data sits in a Singles table in the database, checked there and its there. But when I tried to use frappe_client I get an error saying there is no doctype named Singles.
Got everything working nicely except how to restart my supervisor application.
Im running:
os.system(“supervisorctl stop ussd”)
os.system(“supervisorctl start ussd”)
to restart using an event hoot with ‘all’, so every 3 minutes there is a check. But Im suspecting that when frappe runs its not using super user and these commands are not being executed.
Any idea how I can restart supervisor using the python hook that I created?