import - non parallel version of link rancher to org
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
import os
|
||||
from multiprocessing import cpu_count, Pool
|
||||
|
||||
from django.core.management.base import BaseCommand
|
||||
@@ -5,6 +6,19 @@ from django.db import connection
|
||||
|
||||
from .link_ranchers_parallel_worker import process_city
|
||||
|
||||
os.environ["DJANGO_ALLOW_ASYNC_UNSAFE"] = "true"
|
||||
|
||||
|
||||
def run_worker(chunk):
|
||||
import os
|
||||
import django
|
||||
|
||||
os.environ.setdefault(
|
||||
"DJANGO_SETTINGS_MODULE",
|
||||
"Rasaddam_Backend.settings"
|
||||
)
|
||||
django.setup()
|
||||
|
||||
|
||||
class Command(BaseCommand):
|
||||
help = "Parallel link ranchers to cooperative by city"
|
||||
@@ -20,6 +34,14 @@ class Command(BaseCommand):
|
||||
from apps.herd.models import Rancher
|
||||
workers = options['worker']
|
||||
|
||||
from multiprocessing import get_context
|
||||
|
||||
chunks = self.prepare_chunks()
|
||||
|
||||
ctx = get_context("spawn")
|
||||
with ctx.Pool(processes=options["workers"]) as pool:
|
||||
pool.map(run_worker, chunks)
|
||||
|
||||
city_ids = (
|
||||
Rancher.objects.filter(city__isnull=False)
|
||||
.values_list('city_id', flat=True)
|
||||
|
||||
Reference in New Issue
Block a user