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

Process import dataset and result in separate methods #542

Conversation

thauk-copperleaf
Copy link
Contributor

This refactoring allows imports to be done asynchronously (in our case, using celery). We've been using this for months now, and I thought it was finally time to push the changes back upstream.

@thauk-copperleaf
Copy link
Contributor Author

@bmihelac I'm not merging this immediately because I'd like to get your opinion first :)

@bmihelac
Copy link
Member

bmihelac commented Nov 3, 2016

@thauk-copperleaf I had take just a quick look for now and would dedicate more time later today.

Do I get this right - when async importing, you overrideprocess_dataset that hands out job to celery and immediately return some result that process_result displays?

@thauk-copperleaf
Copy link
Contributor Author

Yes, process_dataset() divides the dataset into chunks, creates a group of celery task signatures for each chunk, and then uses chord to run the group. The immediate return value is an ImportResult model object (internal to us) that has a TaskState that defines if it's finished or not. (How that works is outside the scope of the library.)

@thauk-copperleaf
Copy link
Contributor Author

We subclass ImportExportMixin and override its process_result() method in order to handle both asynchronous and synchronous imports.

@bmihelac
Copy link
Member

bmihelac commented Nov 4, 2016

Everything looks good to me.

@shaggyfrog shaggyfrog merged commit 895e29a into django-import-export:master Nov 15, 2016
@thauk-copperleaf thauk-copperleaf deleted the process-import-dataset-and-result branch November 15, 2016 18:01
@mateuspadua
Copy link

Hello everyone, there are some example how to import data using Celery? I didn't find anything in documentation. Thanks :)
http://django-import-export.readthedocs.io/en/stable/search.html?q=celery&check_keywords=yes&area=default#

@thauk-copperleaf
Copy link
Contributor Author

@mateuspadua You'll have to build the tooling on your own. There's no library to provide the integration out of the box.

@mateuspadua
Copy link

@thauk-copperleaf thanks for reply, :)

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

Successfully merging this pull request may close these issues.

None yet

5 participants