Skip to content

Commit 3ac2c54

Browse files
committed
add performance time
1 parent 59415ef commit 3ac2c54

1 file changed

Lines changed: 16 additions & 16 deletions

File tree

woco/workflow.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import argparse
33
import re
44
import logging
5-
import json
5+
import time
66

77
from pathlib import Path
88
from datetime import datetime
@@ -81,8 +81,11 @@ def run_workflow(
8181

8282
# Request
8383
logger.info(f"Create product: {payload['name']}")
84+
start_time = time.time()
8485
product = self._woocommerce.add_products(payload)
85-
logger.info(f"Successfully add {product['id']}, {product['name']}")
86+
end_time = time.time()
87+
logger.info(f"Successfully add {product['id']}, {product['name']}. Total time: {end_time - start_time}")
88+
8689
payloads.append({
8790
**payload,
8891
'id': product['id'],
@@ -102,18 +105,6 @@ def run_workflow(
102105
raise ValueError(ex)
103106
sys.exit(1)
104107

105-
def run_update_workflow(
106-
self, config_path: str, key_path: str
107-
):
108-
try:
109-
path = os.path.join(config_path)
110-
config = read_config_file(path)
111-
models = config['model']
112-
raise NotImplementedError
113-
except Exception as ex:
114-
raise ValueError(ex)
115-
sys.exit(1)
116-
117108
def run_remove_workflow(
118109
self, config_path: str, key_path: str
119110
):
@@ -130,19 +121,28 @@ def run_remove_workflow(
130121
product_image_ids = item['image_ids']
131122

132123
logger.info(f"Delete product: {product_id}")
124+
start_time = time.time()
133125
self._woocommerce.remove_product(product_id)
134-
logger.info(f"Successfully remove {product_id}")
126+
end_time = time.time()
127+
logger.info(f"Successfully remove {product_id}. Total time: {end_time - start_time}")
135128

136129
except Exception as ex:
137130
raise ValueError(ex)
138131
sys.exit(1)
139132

133+
def run_update_workflow(
134+
self, config_path: str, key_path: str
135+
):
136+
raise NotImplementedError
140137

141138
def _fetch_assets(self, image: dict) -> list[dict]:
142139
logger.info('Fetch images from media storage')
143140
assets = self._media_storage.get_assets(
144141
dir=image['path'],
145-
sort_by=(image['sort']['name'], image['sort']['order_by']),
142+
sort_by=(
143+
image['sort']['name'] or 'uploaded_at',
144+
image['sort']['order_by'] or 'asc'
145+
),
146146
max_results=image.get('max_results') or 2,
147147
excludes=image['excludes']
148148
)

0 commit comments

Comments
 (0)