The files in the folder are sqlite databases. Each of them defines a 
"connection" in Django settings, that one can use through the ORM using 
"django.db.connections". Settings are loaded when the app starts.

So there is no way I think that I can use the ORM with these sqlite 
databases without restarting the app when I add a new one, in order the ORM 
to be aware that there is a new connection available.

I first fill my main database with the names of the connections, then add 
each of them to the settings.DATABASES, then the app starts... I know, it 
looks bad, but I couldn't find a better way.


Le lundi 25 avril 2016 15:27:24 UTC+2, Jason Garber a écrit :
>
> Hi Julien,
>
> You can create another background process with it's own settings using 
> WSGIStartupScript and a separate WSGIProcessGroup with 1 process and 1 
> thread.
>
> However it seems odd that you would do this on startup and put it in a 
> database.  Why does it need done on each startup if it is in the DB?
>
> Perhaps just create another table in the db with a status: empty, 
> scanning, filled.
>
> On a timed interval or startup you could basic locking to lock that table, 
> and only one process/thread would get to do.the work.
>
> J
> On Apr 25, 2016 9:13 AM, "Julien Delafontaine" <[email protected] 
> <javascript:>> wrote:
>
>> Hi again,
>>
>> It seems trememdously hard in Django to run code only once when the app 
>> starts, instead it is executed once per process. I tried wsgi.py, 
>> settings.py, apps.py, and many others. Is it a good idea to use the 
>> --service-script option for that purpose?
>>
>> I want to scan a folder when the app starts to update my database 
>> according to the files found there.
>> Like
>>     --service-script scan myapp/scripts/scan_folders.py
>> even if I don't use the service anymore after that.
>>
>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "modwsgi" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to [email protected] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/modwsgi.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to