Heroku RQ (Redis Queue) Django Error: “Apps aren't loaded yet.”
I have a functional Django app that has many Google Text-To-Speech API calls and database reads/writes in my view. When testing locally it takes about 3 seconds to load a page, but when I deploy the app live to Heroku it takes about 15 seconds to load the webpage. So I am trying to reduce load time.
I came across this article: https://devcenter.heroku.com/articles/python-rq that suggests I should use background tasks by queueing jobs to workers using an RQ (Redis Queue) library. I followed their steps and included their worker.py
file in the same directory as my manage.py
file (not sure if that's the right place to put it). I wanted to test it out locally with a dummy function and view to see if it would run without errors.
# views.py
from rq import Queue
from worker import conn
def dummy(foo):
return 2
def my_view(request):
q = Queue(connection=conn)
for i in range(10):
dummy_foo = q.enqueue(dummy, "howdy")
return render(request, 'dummy.html', {})
In separate terminals I run:
$ python worker.py
$ python manage.py runserver
But when loading the webpage I received many "Apps aren't loaded yet."
error messages in the python worker.py
terminal. I haven't tried to deploy to Heroku yet, but I'm wondering why I am I getting this error message locally?
python django heroku redis
add a comment |
I have a functional Django app that has many Google Text-To-Speech API calls and database reads/writes in my view. When testing locally it takes about 3 seconds to load a page, but when I deploy the app live to Heroku it takes about 15 seconds to load the webpage. So I am trying to reduce load time.
I came across this article: https://devcenter.heroku.com/articles/python-rq that suggests I should use background tasks by queueing jobs to workers using an RQ (Redis Queue) library. I followed their steps and included their worker.py
file in the same directory as my manage.py
file (not sure if that's the right place to put it). I wanted to test it out locally with a dummy function and view to see if it would run without errors.
# views.py
from rq import Queue
from worker import conn
def dummy(foo):
return 2
def my_view(request):
q = Queue(connection=conn)
for i in range(10):
dummy_foo = q.enqueue(dummy, "howdy")
return render(request, 'dummy.html', {})
In separate terminals I run:
$ python worker.py
$ python manage.py runserver
But when loading the webpage I received many "Apps aren't loaded yet."
error messages in the python worker.py
terminal. I haven't tried to deploy to Heroku yet, but I'm wondering why I am I getting this error message locally?
python django heroku redis
do you have redis running locally?
– 4140tm
Jan 2 at 15:37
I didn't (total Redis noob here). But I just tried running redis-server in a third separate terminal and it gave me the same error.
– user3562967
Jan 2 at 16:35
add a comment |
I have a functional Django app that has many Google Text-To-Speech API calls and database reads/writes in my view. When testing locally it takes about 3 seconds to load a page, but when I deploy the app live to Heroku it takes about 15 seconds to load the webpage. So I am trying to reduce load time.
I came across this article: https://devcenter.heroku.com/articles/python-rq that suggests I should use background tasks by queueing jobs to workers using an RQ (Redis Queue) library. I followed their steps and included their worker.py
file in the same directory as my manage.py
file (not sure if that's the right place to put it). I wanted to test it out locally with a dummy function and view to see if it would run without errors.
# views.py
from rq import Queue
from worker import conn
def dummy(foo):
return 2
def my_view(request):
q = Queue(connection=conn)
for i in range(10):
dummy_foo = q.enqueue(dummy, "howdy")
return render(request, 'dummy.html', {})
In separate terminals I run:
$ python worker.py
$ python manage.py runserver
But when loading the webpage I received many "Apps aren't loaded yet."
error messages in the python worker.py
terminal. I haven't tried to deploy to Heroku yet, but I'm wondering why I am I getting this error message locally?
python django heroku redis
I have a functional Django app that has many Google Text-To-Speech API calls and database reads/writes in my view. When testing locally it takes about 3 seconds to load a page, but when I deploy the app live to Heroku it takes about 15 seconds to load the webpage. So I am trying to reduce load time.
I came across this article: https://devcenter.heroku.com/articles/python-rq that suggests I should use background tasks by queueing jobs to workers using an RQ (Redis Queue) library. I followed their steps and included their worker.py
file in the same directory as my manage.py
file (not sure if that's the right place to put it). I wanted to test it out locally with a dummy function and view to see if it would run without errors.
# views.py
from rq import Queue
from worker import conn
def dummy(foo):
return 2
def my_view(request):
q = Queue(connection=conn)
for i in range(10):
dummy_foo = q.enqueue(dummy, "howdy")
return render(request, 'dummy.html', {})
In separate terminals I run:
$ python worker.py
$ python manage.py runserver
But when loading the webpage I received many "Apps aren't loaded yet."
error messages in the python worker.py
terminal. I haven't tried to deploy to Heroku yet, but I'm wondering why I am I getting this error message locally?
python django heroku redis
python django heroku redis
asked Jan 2 at 15:33
user3562967user3562967
589
589
do you have redis running locally?
– 4140tm
Jan 2 at 15:37
I didn't (total Redis noob here). But I just tried running redis-server in a third separate terminal and it gave me the same error.
– user3562967
Jan 2 at 16:35
add a comment |
do you have redis running locally?
– 4140tm
Jan 2 at 15:37
I didn't (total Redis noob here). But I just tried running redis-server in a third separate terminal and it gave me the same error.
– user3562967
Jan 2 at 16:35
do you have redis running locally?
– 4140tm
Jan 2 at 15:37
do you have redis running locally?
– 4140tm
Jan 2 at 15:37
I didn't (total Redis noob here). But I just tried running redis-server in a third separate terminal and it gave me the same error.
– user3562967
Jan 2 at 16:35
I didn't (total Redis noob here). But I just tried running redis-server in a third separate terminal and it gave me the same error.
– user3562967
Jan 2 at 16:35
add a comment |
1 Answer
1
active
oldest
votes
You didn't post the code of worker.py
, but I'd wager it does not properly initialize Django. Take a look at the contents of manage.py
to see an example. So, if worker.py
tries to instantiate (or even import) any models, views, etc, you'll get that kind of error. Django needs to resolve settings.py
(among other things), then use that to look up database settings, resolve models/relationships, etc.
Simplest path is to use django-rq
, a simple library that integrates RQ and Django to handle all this. Your worker.py
essentially just becomes python manage.py rqworker
.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009050%2fheroku-rq-redis-queue-django-error-apps-arent-loaded-yet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You didn't post the code of worker.py
, but I'd wager it does not properly initialize Django. Take a look at the contents of manage.py
to see an example. So, if worker.py
tries to instantiate (or even import) any models, views, etc, you'll get that kind of error. Django needs to resolve settings.py
(among other things), then use that to look up database settings, resolve models/relationships, etc.
Simplest path is to use django-rq
, a simple library that integrates RQ and Django to handle all this. Your worker.py
essentially just becomes python manage.py rqworker
.
add a comment |
You didn't post the code of worker.py
, but I'd wager it does not properly initialize Django. Take a look at the contents of manage.py
to see an example. So, if worker.py
tries to instantiate (or even import) any models, views, etc, you'll get that kind of error. Django needs to resolve settings.py
(among other things), then use that to look up database settings, resolve models/relationships, etc.
Simplest path is to use django-rq
, a simple library that integrates RQ and Django to handle all this. Your worker.py
essentially just becomes python manage.py rqworker
.
add a comment |
You didn't post the code of worker.py
, but I'd wager it does not properly initialize Django. Take a look at the contents of manage.py
to see an example. So, if worker.py
tries to instantiate (or even import) any models, views, etc, you'll get that kind of error. Django needs to resolve settings.py
(among other things), then use that to look up database settings, resolve models/relationships, etc.
Simplest path is to use django-rq
, a simple library that integrates RQ and Django to handle all this. Your worker.py
essentially just becomes python manage.py rqworker
.
You didn't post the code of worker.py
, but I'd wager it does not properly initialize Django. Take a look at the contents of manage.py
to see an example. So, if worker.py
tries to instantiate (or even import) any models, views, etc, you'll get that kind of error. Django needs to resolve settings.py
(among other things), then use that to look up database settings, resolve models/relationships, etc.
Simplest path is to use django-rq
, a simple library that integrates RQ and Django to handle all this. Your worker.py
essentially just becomes python manage.py rqworker
.
answered Jan 7 at 14:36
bimsapibimsapi
3,42011425
3,42011425
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54009050%2fheroku-rq-redis-queue-django-error-apps-arent-loaded-yet%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
do you have redis running locally?
– 4140tm
Jan 2 at 15:37
I didn't (total Redis noob here). But I just tried running redis-server in a third separate terminal and it gave me the same error.
– user3562967
Jan 2 at 16:35