Thursday, January 3, 2019

Re: Best way to submit application cmd, then download a resulting file?

Hi Chris,


The problem you describe does not require Django at all to be solved. 


WRT process parameter input, what you need here is a simple Web based UI with a basic form. Of course Django can do it, but if you don't need features such as the ORM, admin... you can implement it with a couple of lines using lighter frameworks (e.g. Tornado).


The point about monitoring  the process requires first that this process is able to provide a feedback on demand. On *nix systems, this can be done by handling one of the USR signals (e.g. SIG_USR1) and of course implementing the process in non blocking mode (to be able to handle the USR signal while computing). 


How the feedback is returned to the end user is another story. Real time feedback in Web apps is preferably done using Web sockets (rather than polling periodically the server from JS code on the UI page). Who will push the feedback on the socket ? It can be the computation process itself, supposing appropriate connection information are passed to it. But it is cleaner to separate concerns and isolate this in a monitoring specialized layer, communicating with the computation process via Unix sockets for instance or capturing its stdout and grabbing dedicated messages in it (e.g. a message like "PROGRESS: 30"). One option for implementing this monitor is using job Queues, as provided in the multiprocess part of Python standard lib. One you also use Celery, RQ or any job queue framework, but chances are that this would be overkill (especially Celery). RQ is maybe a good choice here, since very lightweight and having RabbitMQ as its only dependency.


Hope this helps


Regards

Eric



From: django-users@googlegroups.com <django-users@googlegroups.com> on behalf of Chris Robinson <gernatch@gmail.com>
Sent: Wednesday, January 2, 2019 10:05:39 PM
To: Django users
Subject: Best way to submit application cmd, then download a resulting file?
 
Hello, 

I'm going to attempt to generalize my question to make this easier to answer. 

Lets say I have a simple terminal based application (e.g. multiply_by_two) that takes a number argument, then multiplies that number by 2, and returns the result into a result.txt file. 

I would enter something like this:
multiply_by_two -n 6

The -n flag asks what number I would like to multiply by 2. The result of this would be a result.txt, containing the number 12 inside. 


What I would like to do is develop a simple Djano application that contains a text field allowing me to input the number 6, then click "Submit."

This job will start on the server by running my custom multiply_by_two application with my input parameter (6), but when the job is finished and the result.txt is available, the browser will automatically download the file. 

To make this a tad bit more complex, lets say that the job takes 2 minutes to run. What would be the best way to monitor the job? Maybe I accidentally close the window.

Not looking for anyone to solve this, I'm just new to Django and want to know if someone can give me any pointers on where to start. Are there any apps existing that will help me not need to write everything from scratch, especially if 'monitoring' is needed? Would Celery be ideal for this?

Thanks for any input!

Regards,
Chris

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/6ba9ac84-366c-4c91-b068-3ecc65c27a9d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment