Redirecting django app webpages through celery task

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Redirecting django app webpages through celery task

Mohammed Noor
Hello guys,

I need to create  a django application that takes a repository url, builds the code located in the url location and runs a few tests. If the tests are successfull, it tags the code and then sends an email to the user notifying the same. 

Because the building process takes a long time, I have used celery to run it as a background process. I am implementing the following design.

def main_function(request):
          # lines_of_code
          result=tasks.BuildCodeAndVerify.delay(args)
          #few more lines of code
          return (request,'waiting_page.html',context)

Note: The waiting page has a progress bar that reads percentage progress from my celery task i.e BuildCodeAndVerify. 

Now, I am facing two problems:

1. If the build is successful, i need to redirect from the waiting page and update the html view with a success page and a summary of the build. How do i make the celery task redirect a webpage? Also, it needs to pass a dictionary to the webpage containing a summary. How do i do all this?

2. Is it possible to pass the request object as an argument like  BuildCodeAndVerify(request,other_args). Because whenever I try i get an error saying. "WSGI error: type object is not JSON serializable." 


And I have very limited django and python knowledge so please go easy on me if my questions look naive. 

Would be grateful for any help and advice i can get.

Thanks a lot!
Khasim

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CABANScQFwPxUi7p2-ePTe5k9Sap5wGkABwSrtcCX50EbNZQpoQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting django app webpages through celery task

Jason Johns
1, you can't.  you can expose an URL and view for your client-side app to request for task state.  if response of state is "SUCCESS", then you can trigger a client side redirect.
2. when using celery, pass in only the data it's needed, such as a db record ID, and do all your retrievals inside the task.

Some reading for celery best practices:

https://khashtamov.com/en/celery-best-practices-practical-approach/

On Monday, June 11, 2018 at 9:14:42 AM UTC-4, Mohammed Noor wrote:
Hello guys,

I need to create  a django application that takes a repository url, builds the code located in the url location and runs a few tests. If the tests are successfull, it tags the code and then sends an email to the user notifying the same. 

Because the building process takes a long time, I have used celery to run it as a background process. I am implementing the following design.

def main_function(request):
          # lines_of_code
          result=tasks.BuildCodeAndVerify.delay(args)
          #few more lines of code
          return (request,'waiting_page.html',context)

Note: The waiting page has a progress bar that reads percentage progress from my celery task i.e BuildCodeAndVerify. 

Now, I am facing two problems:

1. If the build is successful, i need to redirect from the waiting page and update the html view with a success page and a summary of the build. How do i make the celery task redirect a webpage? Also, it needs to pass a dictionary to the webpage containing a summary. How do i do all this?

2. Is it possible to pass the request object as an argument like  BuildCodeAndVerify(request,other_args). Because whenever I try i get an error saying. "WSGI error: type object is not JSON serializable." 


And I have very limited django and python knowledge so please go easy on me if my questions look naive. 

Would be grateful for any help and advice i can get.

Thanks a lot!
Khasim

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/2c43e673-d203-4a78-882f-1723c9c9bd0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Redirecting django app webpages through celery task

Mohammed Noor
But isn't request a multi object type dictionary? What's the problem with passing a dictionary as a parameter.

On Mon, Jun 11, 2018 at 7:40 PM, Jason <[hidden email]> wrote:
1, you can't.  you can expose an URL and view for your client-side app to request for task state.  if response of state is "SUCCESS", then you can trigger a client side redirect.
2. when using celery, pass in only the data it's needed, such as a db record ID, and do all your retrievals inside the task.

Some reading for celery best practices:

https://khashtamov.com/en/celery-best-practices-practical-approach/


On Monday, June 11, 2018 at 9:14:42 AM UTC-4, Mohammed Noor wrote:
Hello guys,

I need to create  a django application that takes a repository url, builds the code located in the url location and runs a few tests. If the tests are successfull, it tags the code and then sends an email to the user notifying the same. 

Because the building process takes a long time, I have used celery to run it as a background process. I am implementing the following design.

def main_function(request):
          # lines_of_code
          result=tasks.BuildCodeAndVerify.delay(args)
          #few more lines of code
          return (request,'waiting_page.html',context)

Note: The waiting page has a progress bar that reads percentage progress from my celery task i.e BuildCodeAndVerify. 

Now, I am facing two problems:

1. If the build is successful, i need to redirect from the waiting page and update the html view with a success page and a summary of the build. How do i make the celery task redirect a webpage? Also, it needs to pass a dictionary to the webpage containing a summary. How do i do all this?

2. Is it possible to pass the request object as an argument like  BuildCodeAndVerify(request,other_args). Because whenever I try i get an error saying. "WSGI error: type object is not JSON serializable." 


And I have very limited django and python knowledge so please go easy on me if my questions look naive. 

Would be grateful for any help and advice i can get.

Thanks a lot!
Khasim

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/2c43e673-d203-4a78-882f-1723c9c9bd0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
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 [hidden email].
To post to this group, send email to [hidden email].
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/CABANScTisa5K_Y%3DxD_YfbQhUAEAqm4gNnAs3-jkKmQaJx7TRxw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.