Code Monkey home page Code Monkey logo

Comments (5)

OmarWKH avatar OmarWKH commented on August 24, 2024

I think two things are happening:

1- Reloading before success: onSuccess is responsible for updating the UI (turning the bar green). You override onSuccess, so the task is finished but the UI isn't updated. To preserve the default behaviour when overriding, call this.onSuccessDefault in your custom handler and give it all the arguments. Like this:

onSuccess: function(...args) {
  this.onSuccessDefault(...args);
  // Custom success behaviour
}

2- Continuous reloading: The task result is still stored in the backend. So when the frontend asks for task status, it finds that the task finished successfully and triggers the onSuccess handler which causes reloading. So everything is working as expected. What's your desired behaviour?

from celery-progress.

bradsolves avatar bradsolves commented on August 24, 2024

Thank you very much for your prompt response. With respect to the continuous reloading, that makes perfect sense; the task result is SUCCESS so it will fire the onSuccess handler upon page load. I added some logic to check for the presence of a different UI element to determine whether the page had already reloaded, which solved that issue.

With respect tot he default handler, though, I am now receiving an error stating that this.onSuccessDefault does not exist. My script is now:

    {% if task_id %}
        <script src="{% static 'celery_progress/celery_progress.js' %}"></script>
        <script>
            $(function () {
                var progressUrl = "{% url 'celery_progress:task_status' task_id %}"
                CeleryProgressBar.initProgressBar(progressUrl, {
                    onSuccess: function(...args) {
                        this.onSuccessDefault(...args);
                        if (!$('#comparison3-tab').hasClass("disabled")) {
                            location.reload();
                        }
                    }
                });
            });
        </script>
    {% endif %}

and the error received is:

(index):1084 Uncaught (in promise) TypeError: this.onSuccessDefault is not a function
    at CeleryProgressBar.onSuccess ((index):1084)
    at CeleryProgressBar.onData (celery_progress.js:80)
    at CeleryProgressBar.connect (celery_progress.js:115)

from celery-progress.

OmarWKH avatar OmarWKH commented on August 24, 2024

You are right. I was testing on the unreleased version.

The way to reference onSuccessDefault was changed in #62 but it's not included in the latest release yet.

On the current version (0.0.14), use CeleryProgressBar.onSuccessDefault.

On later versions, use this.onSuccessDefault.

@czue

from celery-progress.

bradsolves avatar bradsolves commented on August 24, 2024

works great! Thanks!

from celery-progress.

czue avatar czue commented on August 24, 2024

Sorry about that!

I just pushed a new release (0.1.0 - because I don't really know why I ever started with 0.0... 🤷‍♂️ ). Feel free to install that one and let me know if there are any issues!

from celery-progress.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.