Redirecting django app webpages through celery task

132 views
Skip to first unread message

Mohammed Noor

unread,
Jun 11, 2018, 9:14:42 AM6/11/18
to django...@googlegroups.com
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

Jason

unread,
Jun 11, 2018, 10:10:37 AM6/11/18
to Django users
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:

Mohammed Noor

unread,
Jun 12, 2018, 2:55:29 AM6/12/18
to django...@googlegroups.com
But isn't request a multi object type dictionary? What's the problem with passing a dictionary as a parameter.

--
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 django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
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 all
Reply to author
Forward
0 new messages