forked from teamhephy/controller
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request teamhephy#34 from jianxiaoguo/dev
test(controller): add command unittest
- Loading branch information
Showing
13 changed files
with
181 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import uuid | ||
import time | ||
import logging | ||
from django.utils import timezone | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from api.models import Config | ||
from api.tasks import measure_config | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Management command for push data to influxdb""" | ||
"""Management command for push data to manager""" | ||
|
||
def handle(self, *args, **options): | ||
if settings.WORKFLOW_MANAGER_URL is not None: | ||
timestamp = time.time() | ||
task_id = uuid.uuid4().hex | ||
print(f"pushing {task_id} limits to workflow_manager when {timezone.now()}") | ||
logger.info(f"pushing {task_id} limits to workflow_manager when {timezone.now()}") | ||
config_list = [] | ||
for config in Config.objects.all(): | ||
config_list.extend(config.to_measurements(timestamp)) | ||
if len(config_list) % 1000 == 0: | ||
measure_config.delay(config_list) | ||
config_list = [] | ||
if len(config_list) > 0: | ||
measure_config.delay(*config_list) | ||
print(f"pushed {task_id} limits to workflow_manager when {timezone.now()}") | ||
measure_config.delay(config_list) | ||
logger.info(f"pushed {task_id} limits to workflow_manager when {timezone.now()}") | ||
self.stdout.write("done") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import uuid | ||
import time | ||
import logging | ||
from django.utils import timezone | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from api.models import Resource | ||
from api.tasks import measure_resources | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Management command for push data to influxdb""" | ||
"""Management command for push data to manager""" | ||
|
||
def handle(self, *args, **options): | ||
if settings.WORKFLOW_MANAGER_URL is not None: | ||
timestamp = time.time() | ||
task_id = uuid.uuid4().hex | ||
print(f"pushing {task_id} resources to workflow_manager when {timezone.now()}") | ||
logger.info(f"pushing {task_id} resources to workflow_manager when {timezone.now()}") | ||
resource_list = [] | ||
for resource in Resource.objects.all(): | ||
resource_list.extend(resource.to_to_measurements(timestamp)) | ||
resource_list.extend(resource.to_measurements(timestamp)) | ||
if len(resource_list) % 1000 == 0: | ||
measure_resources.delay(resource_list) | ||
resource_list = [] | ||
if len(resource_list) > 0: | ||
measure_resources.delay(*resource_list) | ||
print(f"pushed {task_id} resources to workflow_manager when {timezone.now()}") | ||
measure_resources.delay(resource_list) | ||
logger.info(f"pushed {task_id} resources to workflow_manager when {timezone.now()}") | ||
self.stdout.write("done") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,30 @@ | ||
import uuid | ||
import time | ||
import logging | ||
from django.utils import timezone | ||
from django.core.management.base import BaseCommand | ||
from django.conf import settings | ||
from api.models import Volume | ||
from api.tasks import measure_volumes | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Command(BaseCommand): | ||
"""Management command for push data to influxdb""" | ||
"""Management command for push data to manager""" | ||
|
||
def handle(self, *args, **options): | ||
if settings.WORKFLOW_MANAGER_URL is not None: | ||
timestamp = time.time() | ||
task_id = uuid.uuid4().hex | ||
print(f"pushing {task_id} volumes to workflow_manager when {timezone.now()}") | ||
logger.info(f"pushing {task_id} volumes to workflow_manager when {timezone.now()}") | ||
volume_list = [] | ||
for volume in Volume.objects.all(): | ||
volume_list.extend(volume.to_measurements(timestamp)) | ||
if len(volume_list) % 1000 == 0: | ||
measure_volumes.delay(volume_list) | ||
volume_list = [] | ||
if len(volume_list) > 0: | ||
measure_volumes.delay(*volume_list) | ||
print(f"pushed {task_id} volumes to workflow_manager when {timezone.now()}") | ||
measure_volumes.delay(volume_list) | ||
logger.info(f"pushed {task_id} volumes to workflow_manager when {timezone.now()}") | ||
self.stdout.write("done") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.