Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example template lets_divide.html to README #20

Open
jacobwegner opened this issue Jun 18, 2013 · 9 comments
Open

Add example template lets_divide.html to README #20

jacobwegner opened this issue Jun 18, 2013 · 9 comments

Comments

@jacobwegner
Copy link
Contributor

I'm not very familiar with jQuery plugins, and I'm trying to use jquery-celery with jobtastic for the first time.

It'd be great if README.md had an example template that could help folks like me to get started.

I'd be happy to do a PR for this, but I don't know how to create that example template ;-)

I'm guessing something like:

<html>
    <head>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js" ></script>
        <script type="text/javascript" src="https://raw.github.com/PolicyStat/jquery-celery/master/src/celery.js"></script>
    </head>
    <body>
        <div id="task_id" style="display: none;">
            {{ task_id }}
        </div>
    </body>
</html>
@winhamwr
Copy link
Contributor

Hi Jacob,

Yup. The documentation on jquery-celery is pretty abysmal right now :(

Here's a todo-django project using Jobtastic and jquery-celery that did for a presentation. Hopefully it will help at least a little bit. site_base.html is where the djcelery magic gets hooked in.

It's a pretty good example, since it uses progress and has error/success callbacks, but it's a bit more complex than the simplest example possible.

Would you be willing to take some quick notes on the things that tripped you up starting from that example? Maybe then I could adapt the code there as jquery-celery documentation and then specifically address the things that were confusing/surprising to you.

I'm sorry that I don't have better documentation here already. If you have questions, definitely ask them here and I'll try and respond quickly (at least for the next couple of hours, since I'm already writing documentation for other things anyway).

Thanks for asking the question!
-Wes

@jacobwegner
Copy link
Contributor Author

Thanks; looking at todo-django was enough to get me started.

The error/success callbacks are a big part of why I'm excited to work what you're doing with jobtastic and jquery-celery into some of my projects. I'll come back to this issue later in the week to try and capture my thoughts and do whatever I can to help improve documentation...out of time for today.

Thanks for the great work to date on both of these projects.

@bkeifer
Copy link

bkeifer commented May 11, 2016

I know this is old, but I'd also like to see a sample HTML file. The AJAX part of this whole stack is my weakest point, and that's the one that's not in the docs. =)

@jacobwegner
Copy link
Contributor Author

@bkeifer I'll see if I can add something soon.

@jacobwegner
Copy link
Contributor Author

@bkeifer: I'd love if you took a look at the updated README on this branch with the sample file included.

Ask me follow-up questions here if you're still stuck, and we can iterate on the file/instructions until you're up and running.

Hopefully that way we can end up with a good PR to the README that assumes nothing but gets other new users to the project up and running/

@bkeifer
Copy link

bkeifer commented May 11, 2016

Progress! I'm slowly working through this and getting close.

First thing I found is an extra semicolon on the closing } for on_other (line 39).

The task is started and completes successfully (verified via flower), but I'm getting the "Something went horribly wrong" message on the web page.

My console shows the following URL throwing a 404:
http://localhost:8080/task/f231d5df-fbc6-45b6-acf1-625f4a669134/status/?_=1462994476693

This makes sense, since I don't have anything at /task/ (that I know of, at least...). Where is that URL handled? Is that a part of the Celery setup I missed? If it matters, this is in a Django app.

EDIT: I'm getting there. I think I've almost gotten my view for /task/ working. I'll be happy to provide a copy for the readme once it's working.

@bkeifer
Copy link

bkeifer commented May 12, 2016

So here's what I've got for my /task view. It's not pretty, but it works. Does this jive with what you'd expect to see from the method handling that call?

def task(request, task_id):

    data = 'Fail'
    task = AsyncResult(task_id)

    # Task is still in progress
    if type(task.result) is dict:
        data = {'task': {'result': {}}}
        data['task']['id'] = task_id
        data['task']['status'] = task.state
        data['task']['result']['progress_percent'] = task.result['progress_percent']
    # Task has finished.
    elif type(task.result) is list:
        data = {'task': {}}
        data['task'] = {
            'status': task.state,
            'id': task_id,
            'progress_percent' : 100,
        }

    return HttpResponse(json.dumps(data), content_type='application/json')

@jacobwegner
Copy link
Contributor Author

@bkeifer: You're on the right track.

Celery includes a task status view that you can wire up in the urls.py for your project. It corresponds to the path defined in jquery-celery:

from djcelery.views import task_status
urlpatterns = [
    url(r'^admin/', admin.site.urls),
    ...
    url(r'^task/(?P<task_id>[\w\d\-\.]+)/status/', task_status),
]

@bkeifer
Copy link

bkeifer commented May 14, 2016

That was the missing piece. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants