mpt-extension-sdk 5.9.1__py3-none-any.whl → 5.10.0__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.
@@ -34,12 +34,12 @@ SECRET_KEY = os.getenv(
34
34
  # SECURITY WARNING: don't run with debug turned on in production!
35
35
  DEBUG = True
36
36
 
37
- ALLOWED_HOSTS = ("*")
37
+ ALLOWED_HOSTS = ("*",)
38
38
 
39
39
 
40
40
  # Application definition
41
41
 
42
- INSTALLED_APPS = (
42
+ INSTALLED_APPS = [
43
43
  "django.contrib.admin",
44
44
  "django.contrib.auth",
45
45
  "django.contrib.contenttypes",
@@ -47,9 +47,9 @@ INSTALLED_APPS = (
47
47
  "django.contrib.messages",
48
48
  "django.contrib.staticfiles",
49
49
  "mpt_extension_sdk.runtime.djapp.apps.DjAppConfig",
50
- )
50
+ ]
51
51
 
52
- MIDDLEWARE = (
52
+ MIDDLEWARE = [
53
53
  "django.middleware.security.SecurityMiddleware",
54
54
  "django.contrib.sessions.middleware.SessionMiddleware",
55
55
  "django.middleware.common.CommonMiddleware",
@@ -58,7 +58,7 @@ MIDDLEWARE = (
58
58
  "django.contrib.messages.middleware.MessageMiddleware",
59
59
  "django.middleware.clickjacking.XFrameOptionsMiddleware",
60
60
  "mpt_extension_sdk.runtime.djapp.middleware.MPTClientMiddleware",
61
- )
61
+ ]
62
62
 
63
63
  ROOT_URLCONF = "mpt_extension_sdk.runtime.djapp.conf.urls"
64
64
 
@@ -127,18 +127,14 @@ STATIC_URL = "static/"
127
127
  DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
128
128
 
129
129
  # OpenTelemetry configuration
130
- APPLICATIONINSIGHTS_CONNECTION_STRING = os.getenv(
131
- "APPLICATIONINSIGHTS_CONNECTION_STRING", ""
132
- )
130
+ APPLICATIONINSIGHTS_CONNECTION_STRING = os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING", "")
133
131
  USE_APPLICATIONINSIGHTS = bool(APPLICATIONINSIGHTS_CONNECTION_STRING)
134
132
 
135
133
 
136
134
  if USE_APPLICATIONINSIGHTS: # pragma: no cover
137
135
  logger_provider = LoggerProvider()
138
136
  set_logger_provider(logger_provider)
139
- exporter = AzureMonitorLogExporter(
140
- connection_string=APPLICATIONINSIGHTS_CONNECTION_STRING
141
- )
137
+ exporter = AzureMonitorLogExporter(connection_string=APPLICATIONINSIGHTS_CONNECTION_STRING)
142
138
  logger_provider.add_log_record_processor(BatchLogRecordProcessor(exporter))
143
139
 
144
140
  LOGGING = {
@@ -210,9 +206,7 @@ MPT_PRODUCTS_IDS = os.getenv("MPT_PRODUCTS_IDS", "PRD-1111-1111")
210
206
  MPT_PORTAL_BASE_URL = os.getenv("MPT_PORTAL_BASE_URL", "https://portal.s1.show")
211
207
  MPT_KEY_VAULT_NAME = os.getenv("MPT_KEY_VAULT_NAME", "mpt-key-vault")
212
208
 
213
- MPT_ORDERS_API_POLLING_INTERVAL_SECS = int(
214
- os.getenv("MPT_ORDERS_API_POLLING_INTERVAL_SECS", "120")
215
- )
209
+ MPT_ORDERS_API_POLLING_INTERVAL_SECS = int(os.getenv("MPT_ORDERS_API_POLLING_INTERVAL_SECS", "120"))
216
210
 
217
211
  EXTENSION_CONFIG = {
218
212
  "DUE_DATE_DAYS": "30",
@@ -7,6 +7,7 @@ from http import HTTPStatus
7
7
 
8
8
  import requests
9
9
  from django.conf import settings
10
+ from django.utils.module_loading import import_string
10
11
 
11
12
  from mpt_extension_sdk.core.events.dataclasses import Event
12
13
  from mpt_extension_sdk.core.utils import setup_client
@@ -17,6 +18,7 @@ logger = logging.getLogger(__name__)
17
18
 
18
19
  class EventProducer(ABC):
19
20
  """Abstract base class for event producers."""
21
+
20
22
  def __init__(self, dispatcher):
21
23
  self.dispatcher = dispatcher
22
24
  self.running_event = threading.Event()
@@ -50,16 +52,14 @@ class EventProducer(ABC):
50
52
  def produce_events(self):
51
53
  """Produce events."""
52
54
 
53
- @abstractmethod
54
- def produce_events_with_context(self):
55
- """Produce events with context."""
56
-
57
55
 
58
56
  class OrderEventProducer(EventProducer):
59
57
  """Order event producer."""
58
+
60
59
  def __init__(self, dispatcher):
61
60
  super().__init__(dispatcher)
62
61
  self.client = setup_client()
62
+ self.setup_contexts = import_string(settings.MPT_SETUP_CONTEXTS_FUNC)
63
63
 
64
64
  def produce_events(self):
65
65
  """Produce order events."""
@@ -67,27 +67,20 @@ class OrderEventProducer(EventProducer):
67
67
  with self.sleep(settings.MPT_ORDERS_API_POLLING_INTERVAL_SECS):
68
68
  orders = self.get_processing_orders()
69
69
  logger.info("%d orders found for processing...", len(orders))
70
- for order in orders:
71
- self.dispatcher.dispatch_event(Event(order["id"], "orders", order))
70
+ self.dispatch_events(orders)
72
71
 
73
- def produce_events_with_context(self): # pragma: no cover
74
- """Produce order events with context."""
75
- while self.running:
76
- with self.sleep(settings.MPT_ORDERS_API_POLLING_INTERVAL_SECS):
77
- orders = self.get_processing_orders()
78
- orders, contexts = self.filter_and_enrich(self.client, orders)
79
- logger.info("%d orders found for processing...", len(orders))
80
- for order, context in zip(orders, contexts, strict=False):
81
- self.dispatcher.dispatch_event(
82
- Event(order["id"], "orders", order, context)
83
- )
72
+ def dispatch_events(self, orders):
73
+ """Dispatch events for the given orders."""
74
+ contexts = self.setup_contexts(self.client, orders)
75
+ for context in contexts:
76
+ self.dispatcher.dispatch_event(Event(context.order_id, "orders", context))
84
77
 
85
78
  def get_processing_orders(self):
86
79
  """Get processing orders."""
87
80
  orders = []
88
- rql_query = RQLQuery().agreement.product.id.in_(
89
- settings.MPT_PRODUCTS_IDS
90
- ) & RQLQuery(status="processing")
81
+ rql_query = RQLQuery().agreement.product.id.in_(settings.MPT_PRODUCTS_IDS) & RQLQuery(
82
+ status="processing"
83
+ )
91
84
  url = (
92
85
  f"/commerce/orders?{rql_query}&select=audit,parameters,lines,subscriptions,"
93
86
  f"subscriptions.lines,agreement,buyer,seller&order=audit.created.at"
@@ -105,9 +98,7 @@ class OrderEventProducer(EventProducer):
105
98
  page = response.json()
106
99
  orders.extend(page["data"])
107
100
  else:
108
- logger.warning(
109
- "Order API error: %s %s", response.status_code, response.content
110
- )
101
+ logger.warning("Order API error: %s %s", response.status_code, response.content)
111
102
  return []
112
103
  offset += limit
113
104
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mpt-extension-sdk
3
- Version: 5.9.1
3
+ Version: 5.10.0
4
4
  Summary: Extensions SDK for SoftwareONE Marketplace Platform
5
5
  Author: SoftwareOne AG
6
6
  License: Apache-2.0 license
@@ -35,20 +35,20 @@ mpt_extension_sdk/runtime/djapp/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm
35
35
  mpt_extension_sdk/runtime/djapp/apps.py,sha256=CFyyZbRUEurKl5fTYCKRGRvfcmgMqWdE9wq049wSwrs,1653
36
36
  mpt_extension_sdk/runtime/djapp/middleware.py,sha256=JX_HvRwTPFvhVf87HOzbOazqtt1OCbti01CJxSzsSPk,651
37
37
  mpt_extension_sdk/runtime/djapp/conf/__init__.py,sha256=zT_Ep9clWx3oXT6EJwY15vUrtk98TqbedXLV0MXptsw,401
38
- mpt_extension_sdk/runtime/djapp/conf/default.py,sha256=yEULNxp3_hkGARkWQ-DUYMTlrzV1DfcxAPMqShcYzA0,6470
38
+ mpt_extension_sdk/runtime/djapp/conf/default.py,sha256=ZjyqHXq8qMJqKWMqnQ2EcRv2eJv7h43GA6njEhMs9R4,6445
39
39
  mpt_extension_sdk/runtime/djapp/conf/urls.py,sha256=g-h1vzwDgCGLliSE2BDjb1eRJevZxZ7ehJrqSis12So,309
40
40
  mpt_extension_sdk/runtime/djapp/management/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  mpt_extension_sdk/runtime/djapp/management/commands/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
42
42
  mpt_extension_sdk/runtime/djapp/management/commands/consume_events.py,sha256=mXUO-Ip1rEpXnchz4iMoe7IWulcyNd2RTZ_QHbxfrBs,1424
43
43
  mpt_extension_sdk/runtime/events/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
44
  mpt_extension_sdk/runtime/events/dispatcher.py,sha256=vpH7eYo3ZD35i9JOKQ6ZqieiNUf6DfSo3-F4bTlUSAo,3348
45
- mpt_extension_sdk/runtime/events/producers.py,sha256=rFUL9eJd1xQNvCBIvv-kxOE5hhX9ruFcyWLdu7x-KMk,4192
45
+ mpt_extension_sdk/runtime/events/producers.py,sha256=8ADzsnJ3rvynvzNjZnK5P8JrenME_QGFywmMaHkWYjg,3727
46
46
  mpt_extension_sdk/runtime/events/utils.py,sha256=6aQVwe9EtUxxictQV9sk8szKC4UXgpQeDmoxdg49fww,2768
47
47
  mpt_extension_sdk/swo_rql/__init__.py,sha256=QrvRDYhpK-Pd3OF-U2aMeazuKm_kbvXwLRIjd9Mm6ok,104
48
48
  mpt_extension_sdk/swo_rql/constants.py,sha256=39BZ78OzdU_dIQtoy-Z_5utXqEXRweIFvM9Zfxg9j5M,171
49
49
  mpt_extension_sdk/swo_rql/query_builder.py,sha256=CG1dm7uJNPPCwWcf9sRD5zLbz-dtgECkQ_pX4QXpJPw,10825
50
- mpt_extension_sdk-5.9.1.dist-info/METADATA,sha256=USDGixJk6lvIul6Lw6veE1SEdi0ZVmLP74pEOqV_9Mg,1358
51
- mpt_extension_sdk-5.9.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
52
- mpt_extension_sdk-5.9.1.dist-info/entry_points.txt,sha256=N8T9gBssEOm_UeBf9ABbGqtlnethrumfMoL4hNYWVFA,146
53
- mpt_extension_sdk-5.9.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
54
- mpt_extension_sdk-5.9.1.dist-info/RECORD,,
50
+ mpt_extension_sdk-5.10.0.dist-info/METADATA,sha256=Dp4mz2j2-XTRX4KkWXdvA8Ts63k6uSPNV1iLTWDdvOI,1359
51
+ mpt_extension_sdk-5.10.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
52
+ mpt_extension_sdk-5.10.0.dist-info/entry_points.txt,sha256=N8T9gBssEOm_UeBf9ABbGqtlnethrumfMoL4hNYWVFA,146
53
+ mpt_extension_sdk-5.10.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
54
+ mpt_extension_sdk-5.10.0.dist-info/RECORD,,