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 support for custom exporter class #6273

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
12 changes: 9 additions & 3 deletions scrapy/extensions/feedexport.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,9 @@ def _get_exporter(self, file, format, *args, **kwargs):

def finish_exporting(self):
if self._exporting:
self.exporter.finish_exporting()
result_or_coro = self.exporter.finish_exporting()
self._exporting = False
return result_or_coro


_FeedSlot = create_deprecated_class(
Expand Down Expand Up @@ -481,11 +482,11 @@ def get_file(slot_):

if slot.itemcount:
# Normal case
slot.finish_exporting()
finish_exporting_maybe_deferred = defer.maybeDeferred(slot.finish_exporting)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove maybe from the name, it's an actual deferred.

elif slot.store_empty and slot.batch_id == 1:
# Need to store the empty file
slot.start_exporting()
slot.finish_exporting()
finish_exporting_maybe_deferred = defer.maybeDeferred(slot.finish_exporting)
else:
# In this case, the file is not stored, so no processing is required.
return None
Expand All @@ -507,6 +508,11 @@ def get_file(slot_):
)
d.addBoth(lambda _: self._pending_deferreds.remove(d))

self._pending_deferreds.append(finish_exporting_maybe_deferred)
finish_exporting_maybe_deferred.addBoth(
lambda _: self._pending_deferreds.remove(finish_exporting_maybe_deferred)
)

return d

def _handle_store_error(self, f, logmsg, spider, slot_type):
Expand Down