use multiprocessing to run scrutinise command
This commit is contained in:
parent
9fd14a0b4a
commit
c1ca2ea616
|
@ -1,3 +1,5 @@
|
|||
import multiprocessing
|
||||
import multiprocessing.pool
|
||||
import requests
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
|
@ -11,7 +13,8 @@ class Command(BaseCommand):
|
|||
|
||||
def handle(self, verbosity, *args, **options):
|
||||
self.verbose = int(verbosity) > 1
|
||||
for service in InstalledService.objects.all():
|
||||
|
||||
def scrutinise(service):
|
||||
if not service.url.endswith('/'):
|
||||
service.url = '%s/' % service.url
|
||||
if self.verbose:
|
||||
|
@ -21,7 +24,7 @@ class Command(BaseCommand):
|
|||
response.raise_for_status()
|
||||
except requests.RequestException as e:
|
||||
print('Error with %s (%r)' % (service.url, e))
|
||||
continue
|
||||
return
|
||||
|
||||
versions = response.json()
|
||||
current_modules = set([x for x in service.service.get_modules(platforms=[service.platform])])
|
||||
|
@ -62,3 +65,6 @@ class Command(BaseCommand):
|
|||
installed_version.version = version
|
||||
installed_version.timestamp = django.utils.timezone.now()
|
||||
installed_version.save()
|
||||
|
||||
with multiprocessing.pool.ThreadPool() as pool:
|
||||
list(pool.imap_unordered(scrutinise, InstalledService.objects.all()))
|
||||
|
|
Loading…
Reference in New Issue