Skip to content

Commit

Permalink
updates migrate_shards command
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciprian Tarta committed Jun 27, 2016
1 parent 2531d43 commit 039b15b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -59,3 +59,4 @@ docs/_build/
target/
.logs/
.idea/
*.swp
2 changes: 1 addition & 1 deletion django_autoshard/__init__.py
@@ -1,4 +1,4 @@
__version__ = '1.1.2'
__version__ = '1.1.3'
__author__ = 'Ciprian Tarta'


Expand Down
21 changes: 2 additions & 19 deletions django_autoshard/management/commands/migrate_shards.py
Expand Up @@ -2,12 +2,6 @@
import time
import six

if six.PY3:
from concurrent.futures import ThreadPoolExecutor
else:
from collections import deque
from threading import Thread

from django.conf import settings
from django.core.management.commands.migrate import Command as DjangoMigrateCommand
from django.db import OperationalError
Expand All @@ -27,19 +21,8 @@ def migrate(self, shard, *args, **options):
self.style.MIGRATE_HEADING('Failed migrating database: %s. Error: %s' % (options['database'], e)))

def run(self, *args, **options):
if six.PY3:
executor = ThreadPoolExecutor(max_workers=10)
for _, shard in settings.SHARDS.items():
executor.submit(self.migrate, *chain((shard,), args), **options)
else:
queue = deque()
for _, shard in settings.SHARDS.items():
queue.append(Thread(target=self.migrate, args=chain((shard,), args), kwargs=options))
workers = 0
while queue:
if workers < 10:
t = queue.popleft()
t.start()
for _, shard in settings.SHARDS.items():
self.migrate(shard, *args, **options)

def handle(self, *args, **options):
options['verbosity'] = 0
Expand Down

0 comments on commit 039b15b

Please sign in to comment.