Skip to content
This repository has been archived by the owner on Jan 16, 2023. It is now read-only.

Commit

Permalink
hide threading behind feature flag
Browse files Browse the repository at this point in the history
  • Loading branch information
antonagestam committed Dec 17, 2016
1 parent 4def512 commit ebc38fb
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions collectfast/management/commands/collectstatic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
cache = caches[collectfast_cache]
debug = getattr(
settings, "COLLECTFAST_DEBUG", getattr(settings, "DEBUG", False))
threads = getattr(settings, "COLLECTFAST_THREADS", False)


class Command(collectstatic.Command):
Expand Down Expand Up @@ -65,9 +66,10 @@ def collect(self):

self.num_skipped_files = 0
start = datetime.datetime.now()
# Copy files asynchronously
ret = super(Command, self).collect()
result = Pool(20).map(self.async_copy_file, self.tasks)
# Copy files asynchronously
if threads:
Pool(threads).map(self.do_copy_file, self.tasks)
self.collect_time = str(datetime.datetime.now() - start)
return ret

Expand Down Expand Up @@ -116,7 +118,7 @@ def get_file_hash(self, storage, path):
file_hash = '"%s"' % hashlib.md5(contents).hexdigest()
return file_hash

def async_copy_file(self, args):
def do_copy_file(self, args):
"""
Attempt to generate an md5 hash of the local file and compare it with
the S3 version's hash before copying the file.
Expand Down Expand Up @@ -155,7 +157,11 @@ def async_copy_file(self, args):
path, prefixed_path, source_storage)

def copy_file(self, path, prefixed_path, source_storage):
self.tasks.append((path, prefixed_path, source_storage))
args = (path, prefixed_path, source_storage)
if threads:
self.tasks.append(args)
else:
self.do_copy_file(args)

def delete_file(self, path, prefixed_path, source_storage):
"""Override delete_file to skip modified time and exists lookups"""
Expand Down

0 comments on commit ebc38fb

Please sign in to comment.