channel-app 0.0.157a10__py3-none-any.whl → 0.0.157a12__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,6 +5,7 @@ from omnisdk.omnitron.models import BatchRequest, ProductImage
5
5
  from channel_app.core import settings
6
6
  from channel_app.core.data import BatchRequestResponseDto, ErrorReportDto
7
7
  from channel_app.core.settings import OmnitronIntegration, ChannelIntegration
8
+ from channel_app.logs.services import LogService
8
9
  from channel_app.omnitron.batch_request import ClientBatchRequest
9
10
  from channel_app.omnitron.constants import ContentType
10
11
 
@@ -12,139 +13,218 @@ from channel_app.omnitron.constants import ContentType
12
13
  class ImageService(object):
13
14
  batch_service = ClientBatchRequest
14
15
 
15
- def update_product_images(self, is_sync=True, is_success_log=True,
16
- add_product_objects=False):
17
- with OmnitronIntegration(
18
- content_type=ContentType.product_image.value) as omnitron_integration:
19
- product_images = omnitron_integration.do_action(
20
- key='get_updated_images')
21
- first_product_image_count = len(product_images)
22
- if add_product_objects:
23
- product_images = product_images and omnitron_integration.do_action(
24
- key='get_product_objects', objects=product_images)
25
-
26
- if not product_images:
27
- if first_product_image_count:
28
- omnitron_integration.batch_request.objects = None
29
- self.batch_service(omnitron_integration.channel_id).to_fail(
30
- omnitron_integration.batch_request
31
- )
32
- return
33
-
34
- product_images: List[ProductImage]
35
-
36
- response_data, reports, data = ChannelIntegration().do_action(
37
- key='send_updated_images',
38
- objects=product_images,
39
- batch_request=omnitron_integration.batch_request,
40
- is_sync=is_sync)
41
-
42
- # tips
43
- response_data: List[BatchRequestResponseDto]
44
- reports: List[ErrorReportDto]
45
- data: List[ProductImage]
46
-
47
- if not is_sync:
48
- if reports[0].is_ok:
49
- self.batch_service(
50
- settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
51
- batch_request=omnitron_integration.batch_request)
52
- else:
53
- is_sync = True
54
-
55
- if reports and (is_success_log or not reports[0].is_ok):
56
- for report in reports:
57
- omnitron_integration.do_action(
58
- key='create_error_report',
59
- objects=report)
60
-
61
- if is_sync:
62
- omnitron_integration.do_action(
63
- key='process_image_batch_requests',
64
- objects=response_data)
65
-
66
- def insert_product_images(self, is_sync=True, is_success_log=True,
67
- add_product_objects=False):
68
- with OmnitronIntegration(
69
- content_type=ContentType.product_image.value) as omnitron_integration:
70
- product_images = omnitron_integration.do_action(
71
- key='get_inserted_images')
72
- first_product_image_count = len(product_images)
73
-
74
- if add_product_objects:
75
- product_images = product_images and omnitron_integration.do_action(
76
- key='get_product_objects', objects=product_images)
77
-
78
- if not product_images:
79
- if first_product_image_count:
80
- omnitron_integration.batch_request.objects = None
81
- self.batch_service(omnitron_integration.channel_id).to_fail(
82
- omnitron_integration.batch_request
83
- )
84
- return
85
-
86
- product_images: List[ProductImage]
87
-
88
- response_data, reports, data = ChannelIntegration().do_action(
89
- key='send_inserted_images',
90
- objects=product_images,
91
- batch_request=omnitron_integration.batch_request,
92
- is_sync=is_sync)
93
-
94
- # tips
95
- response_data: List[BatchRequestResponseDto]
96
- reports: List[ErrorReportDto]
97
- data: List[ProductImage]
98
-
99
- if not is_sync:
100
- if reports[0].is_ok:
101
- self.batch_service(
102
- settings.OMNITRON_CHANNEL_ID).to_sent_to_remote(
103
- batch_request=omnitron_integration.batch_request)
104
- else:
105
- is_sync = True
106
-
107
- if reports and (is_success_log or not reports[0].is_ok):
108
- for report in reports:
109
- omnitron_integration.do_action(
110
- key='create_error_report',
111
- objects=report)
112
-
113
- if is_sync:
114
- omnitron_integration.do_action(
115
- key='process_image_batch_requests',
116
- objects=response_data)
16
+ def update_product_images(
17
+ self, is_sync=True, is_success_log=True, add_product_objects=False
18
+ ):
19
+ log_service = LogService()
20
+ log_service.create_flow(name="Update Product Images")
21
+
22
+ try:
23
+ with log_service.step("update_product_images"):
24
+ with OmnitronIntegration(
25
+ content_type=ContentType.product_image.value
26
+ ) as omnitron_integration:
27
+ with log_service.step("get_updated_images"):
28
+ product_images = omnitron_integration.do_action(
29
+ key="get_updated_images"
30
+ )
31
+
32
+ first_product_image_count = len(product_images)
33
+ if add_product_objects:
34
+ with log_service.step("get_product_objects"):
35
+ product_images = (
36
+ product_images
37
+ and omnitron_integration.do_action(
38
+ key="get_product_objects", objects=product_images
39
+ )
40
+ )
41
+
42
+ if not product_images:
43
+ if first_product_image_count:
44
+ omnitron_integration.batch_request.objects = None
45
+ with log_service.step("batch_to_fail"):
46
+ self.batch_service(
47
+ omnitron_integration.channel_id
48
+ ).to_fail(omnitron_integration.batch_request)
49
+ return
50
+
51
+ product_images: List[ProductImage]
52
+
53
+ with log_service.step("send_updated_images"):
54
+ response_data, reports, data = ChannelIntegration().do_action(
55
+ key="send_updated_images",
56
+ objects=product_images,
57
+ batch_request=omnitron_integration.batch_request,
58
+ is_sync=is_sync,
59
+ )
60
+
61
+ # tips
62
+ response_data: List[BatchRequestResponseDto]
63
+ reports: List[ErrorReportDto]
64
+ data: List[ProductImage]
65
+
66
+ if not is_sync:
67
+ if reports[0].is_ok:
68
+ with log_service.step("batch_send_to_remote"):
69
+ self.batch_service(
70
+ settings.OMNITRON_CHANNEL_ID
71
+ ).to_sent_to_remote(
72
+ batch_request=omnitron_integration.batch_request
73
+ )
74
+ else:
75
+ is_sync = True
76
+
77
+ if reports and (is_success_log or not reports[0].is_ok):
78
+ for report in reports:
79
+ with log_service.step("create_error_report"):
80
+ omnitron_integration.do_action(
81
+ key="create_error_report", objects=report
82
+ )
83
+
84
+ if is_sync:
85
+ with log_service.step("process_image_batch_requests"):
86
+ omnitron_integration.do_action(
87
+ key="process_image_batch_requests",
88
+ objects=response_data,
89
+ )
90
+ except Exception as fatal:
91
+ log_service.add_exception(fatal)
92
+ raise
93
+ finally:
94
+ log_service.save()
95
+
96
+ def insert_product_images(
97
+ self, is_sync=True, is_success_log=True, add_product_objects=False
98
+ ):
99
+ log_service = LogService()
100
+ log_service.create_flow(name="Insert Product Images")
101
+
102
+ try:
103
+ with log_service.step("insert_product_images"):
104
+ with OmnitronIntegration(
105
+ content_type=ContentType.product_image.value
106
+ ) as omnitron_integration:
107
+ with log_service.step("get_inserted_images"):
108
+ product_images = omnitron_integration.do_action(
109
+ key="get_inserted_images"
110
+ )
111
+
112
+ first_product_image_count = len(product_images)
113
+
114
+ if add_product_objects:
115
+ with log_service.step("get_product_objects"):
116
+ product_images = (
117
+ product_images
118
+ and omnitron_integration.do_action(
119
+ key="get_product_objects", objects=product_images
120
+ )
121
+ )
122
+
123
+ if not product_images:
124
+ if first_product_image_count:
125
+ omnitron_integration.batch_request.objects = None
126
+ with log_service.step("batch_to_fail"):
127
+ self.batch_service(
128
+ omnitron_integration.channel_id
129
+ ).to_fail(omnitron_integration.batch_request)
130
+ return
131
+
132
+ product_images: List[ProductImage]
133
+
134
+ with log_service.step("send_inserted_images"):
135
+ response_data, reports, data = ChannelIntegration().do_action(
136
+ key="send_inserted_images",
137
+ objects=product_images,
138
+ batch_request=omnitron_integration.batch_request,
139
+ is_sync=is_sync,
140
+ )
141
+
142
+ # tips
143
+ response_data: List[BatchRequestResponseDto]
144
+ reports: List[ErrorReportDto]
145
+ data: List[ProductImage]
146
+
147
+ if not is_sync:
148
+ if reports[0].is_ok:
149
+ with log_service.step("batch_send_to_remote"):
150
+ self.batch_service(
151
+ settings.OMNITRON_CHANNEL_ID
152
+ ).to_sent_to_remote(
153
+ batch_request=omnitron_integration.batch_request
154
+ )
155
+ else:
156
+ is_sync = True
157
+
158
+ if reports and (is_success_log or not reports[0].is_ok):
159
+ for report in reports:
160
+ with log_service.step("create_error_report"):
161
+ omnitron_integration.do_action(
162
+ key="create_error_report", objects=report
163
+ )
164
+
165
+ if is_sync:
166
+ with log_service.step("process_image_batch_requests"):
167
+ omnitron_integration.do_action(
168
+ key="process_image_batch_requests",
169
+ objects=response_data,
170
+ )
171
+ except Exception as fatal:
172
+ log_service.add_exception(fatal)
173
+ raise
174
+ finally:
175
+ log_service.save()
117
176
 
118
177
  def get_image_batch_requests(self, is_success_log=True):
119
- with OmnitronIntegration(create_batch=False) as omnitron_integration:
120
- batch_request_data = omnitron_integration.do_action(
121
- 'get_batch_requests',
122
- params={
123
- "status": ["sent_to_remote", "ongoing"],
124
- "content_type": ContentType.product_image.value})
125
- # tips
126
- batch_request_data: List[BatchRequest]
127
-
128
- for batch_request in batch_request_data:
129
- response_data, reports, data = ChannelIntegration().do_action(
130
- key='check_images',
131
- objects=batch_request,
132
- batch_request=batch_request
133
- )
134
-
135
- # tips
136
- response_data: List[BatchRequestResponseDto]
137
- reports: List[ErrorReportDto]
138
- data: BatchRequest
139
-
140
- if reports and (is_success_log or not reports[0].is_ok):
141
- for report in reports:
142
- omnitron_integration.do_action(
143
- key='create_error_report',
144
- objects=report)
145
-
146
- if response_data:
147
- omnitron_integration.batch_request = batch_request
148
- omnitron_integration.do_action(
149
- key='process_image_batch_requests',
150
- objects=response_data)
178
+ log_service = LogService()
179
+ log_service.create_flow(name="Get Image Batch Requests")
180
+
181
+ try:
182
+ with log_service.step("get_image_batch_requests"):
183
+ with OmnitronIntegration(create_batch=False) as omnitron_integration:
184
+ with log_service.step("get_batch_requests"):
185
+ batch_request_data = omnitron_integration.do_action(
186
+ "get_batch_requests",
187
+ params={
188
+ "status": ["sent_to_remote", "ongoing"],
189
+ "content_type": ContentType.product_image.value,
190
+ },
191
+ )
192
+ # tips
193
+ batch_request_data: List[BatchRequest]
194
+
195
+ for batch_request in batch_request_data:
196
+ with log_service.step("check_images"):
197
+ (
198
+ response_data,
199
+ reports,
200
+ data,
201
+ ) = ChannelIntegration().do_action(
202
+ key="check_images",
203
+ objects=batch_request,
204
+ batch_request=batch_request,
205
+ )
206
+
207
+ # tips
208
+ response_data: List[BatchRequestResponseDto]
209
+ reports: List[ErrorReportDto]
210
+ data: BatchRequest
211
+
212
+ if reports and (is_success_log or not reports[0].is_ok):
213
+ for report in reports:
214
+ with log_service.step("create_error_report"):
215
+ omnitron_integration.do_action(
216
+ key="create_error_report", objects=report
217
+ )
218
+
219
+ if response_data:
220
+ omnitron_integration.batch_request = batch_request
221
+ with log_service.step("process_image_batch_requests"):
222
+ omnitron_integration.do_action(
223
+ key="process_image_batch_requests",
224
+ objects=response_data,
225
+ )
226
+ except Exception as fatal:
227
+ log_service.add_exception(fatal)
228
+ raise
229
+ finally:
230
+ log_service.save()