dnaStreaming 2.2.0__py3-none-any.whl → 2.2.1.dev1__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.
@@ -4,7 +4,7 @@ from dnaStreaming.listener import Listener
4
4
 
5
5
  listener = Listener()
6
6
  quiet_demo = os.getenv('QUIET_DEMO', "false") == "true"
7
- max_secs = 5
7
+ max_secs = 1000
8
8
  print("\n[ACTIVITY] Receiving messages (ASYNC) for {} seconds...\n[0]".format(max_secs), end='')
9
9
 
10
10
 
@@ -12,9 +12,9 @@ def callback(message, subscription_id):
12
12
  callback.counter += 1
13
13
  if not quiet_demo:
14
14
  if message['action'] != 'del':
15
- print('[INFO] [MSG] [{}]: AN: {}, TITLE: {}'.format(callback.counter, message['an'], message['title']))
15
+ print('[INFO] [SUBSCRIPTION]: {} [MSG] [{}]: AN: {}, TITLE: {}'.format(subscription_id, callback.counter, message['an'], message['title']))
16
16
  else:
17
- print('[INFO] [MSG] [{}]: AN: {}, *** DELETE ***'.format(callback.counter, message['an']))
17
+ print('[INFO] [SUBSCRIPTION]: {} [MSG] [{}]: AN: {}, *** DELETE ***'.format(subscription_id, callback.counter, message['an']))
18
18
  else:
19
19
  if callback.counter % 10 == 0:
20
20
  print('[{}]'.format(callback.counter), end='')
dnaStreaming/listener.py CHANGED
@@ -125,19 +125,20 @@ class Listener(object):
125
125
  'Listeners for subscriptions have been configured, set and await message arrival.')
126
126
  return subscription
127
127
 
128
- def listen_async_ha(self, on_message_callback, subscription_id=""):
129
- def ack_message_and_callback(message):
128
+ def listen_async_ha(self, on_message_callback):
129
+ def ack_message_and_callback(message, subscription_path):
130
130
  pubsub_msg = json.loads(message.data)
131
131
  logger.info("Received news message with ID: {}".format(
132
132
  pubsub_msg['data'][0]['id']))
133
133
  news_msg = pubsub_msg['data'][0]['attributes']
134
- on_message_callback(news_msg, subscription_id)
134
+ short_subscription_id = subscription_path.split("/")[-1]
135
+ on_message_callback(news_msg, short_subscription_id)
135
136
  message.ack()
136
137
 
137
138
  main_pubsub_client = pubsub_service.get_client(self.config, MAIN_REGION)
138
139
  backup_pubsub_client = pubsub_service.get_client(self.config, BACKUP_REGION)
139
140
 
140
- subscription_id = subscription_id or self.config.subscription()
141
+ subscription_id = self.config.subscription()
141
142
 
142
143
  if not subscription_id:
143
144
  raise Exception(
@@ -38,8 +38,14 @@ def ha_listen(api_host, user_key, subscription_id, stop_event, main_subscription
38
38
 
39
39
  current_region = MAIN_REGION
40
40
 
41
+ def wrapped_callback(subscription_path):
42
+ def inner_callback(message):
43
+ callback(message, subscription_path)
44
+
45
+ return inner_callback
46
+
41
47
  streaming_pull_future = main_pubsub_client.subscribe(
42
- main_subscription_path, callback=callback)
48
+ main_subscription_path, callback=wrapped_callback(main_subscription_path))
43
49
 
44
50
  while not stop_event.is_set():
45
51
 
@@ -65,10 +71,10 @@ def ha_listen(api_host, user_key, subscription_id, stop_event, main_subscription
65
71
 
66
72
  if active_region == MAIN_REGION:
67
73
  streaming_pull_future = main_pubsub_client.subscribe(
68
- main_subscription_path, callback=callback)
74
+ main_subscription_path, callback=wrapped_callback(main_subscription_path))
69
75
  else: # active_region == BACKUP_REGION
70
76
  streaming_pull_future = backup_pubsub_client.subscribe(
71
- backup_subscription_path, callback=callback)
77
+ backup_subscription_path, callback=wrapped_callback(backup_subscription_path))
72
78
 
73
79
  logger.warning(f"Started listener in region {active_region}")
74
80
 
@@ -1,9 +1,9 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dnaStreaming
3
- Version: 2.2.0
3
+ Version: 2.2.1.dev1
4
4
  Summary: Dow Jones DNA Streaming Project
5
5
  Home-page: https://github.com/dowjones/dj-dna-streams-python
6
- Download-URL: https://github.com/dowjones/dj-dna-streams-python/archive/release-2.2.0.tar.gz
6
+ Download-URL: https://github.com/dowjones/dj-dna-streams-python/archive/release-2.2.1.dev1.tar.gz
7
7
  Author: Zachary Kagan
8
8
  Author-email: zachary.kagan@dowjones.com
9
9
  License: MIT
@@ -1,21 +1,21 @@
1
1
  dnaStreaming/__init__.py,sha256=Brud0G1kzJ2Fu4FtDveQnHraKl7r26zdSdPK0EqrLp4,752
2
2
  dnaStreaming/config.py,sha256=DLNFOvWlj5sLAr39i632yxgWQppYYw_YbUSiUMpy87U,3773
3
3
  dnaStreaming/customer_config.json,sha256=hzrReqREkH-j39vgifA-VVUtnkBtQJO4d2QyF8j9NMo,46
4
- dnaStreaming/listener.py,sha256=QdLlx1CFFNq6SdZVAmo0cc3Rh7TA9tr_iH91CndOzDE,7739
4
+ dnaStreaming/listener.py,sha256=nNARri0SFpo3HbTayYbjNKJiP11VyFhozNLdow8GmjQ,7794
5
5
  dnaStreaming/demo/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
6
  dnaStreaming/demo/pubsub_stream.py,sha256=qaxutRGaEuHoDsGCSkJ8tzoXaZbgugrv3plW9CqGxZE,1617
7
- dnaStreaming/demo/show_ha_stream_async.py,sha256=_a1cbrJAgdsxCn7VfLmxRgLqVfYTEVDrGw8Hf75Y4Yw,1087
7
+ dnaStreaming/demo/show_ha_stream_async.py,sha256=94nQrVwbm39EbE5CB-20RwnhTbe66e7DlyHOXnN_FEY,1162
8
8
  dnaStreaming/demo/show_stream.py,sha256=j42YW5_4mMjzQqcGnNfoY_3ABROf9v84Kjs18OE-wvo,1113
9
9
  dnaStreaming/demo/show_stream_async.py,sha256=QTXKsQywLamZjlrKci-TrsBmQjTlh8pcFsfDL8HsKt8,1026
10
10
  dnaStreaming/services/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
11
  dnaStreaming/services/authentication_service.py,sha256=4g3DpvTS8neeDVnFwDsLP0qu59xgAz0wyXm8a7LhPqs,262
12
- dnaStreaming/services/availability_service.py,sha256=92xROh2nNA2QH_Jev1KFdRQZ45v-Xr4zbqcHc12QItQ,2696
12
+ dnaStreaming/services/availability_service.py,sha256=HtXXtOugj4y9Qzsp-1AcuavvWxshuKyZNbHlQLxcGvU,2953
13
13
  dnaStreaming/services/credentials_service.py,sha256=S9nJl1heuNZzDaTrzgzTF52UshR0aiIw3j-oLzEhsj4,806
14
14
  dnaStreaming/services/pubsub_service.py,sha256=P0YLy6MNXDVcAKsmVcuNf-WKar-LYawpah3dFnFr648,820
15
15
  dnaStreaming/test/__init__.py,sha256=67-6hUa7BZvz64n27sEH0ulQtcg5qH8_Q2ot_XgFdFQ,79
16
16
  dnaStreaming/test/test_config.py,sha256=mJPk-yxv49Zwsj0lHV-zcy8fhhlt0RFyfhbgg74g3Jo,3619
17
- dnaStreaming-2.2.0.dist-info/LICENSE,sha256=l0T3WdIyACkYU-XdqJnaLC5_m1Wa0wJEZSJC4Owc7Y4,1077
18
- dnaStreaming-2.2.0.dist-info/METADATA,sha256=8NO8CSeWSOnKeuv6V__1kdRKzAL9dcJ8ngjH8Sde8bU,7544
19
- dnaStreaming-2.2.0.dist-info/WHEEL,sha256=GJ7t_kWBFywbagK5eo9IoUwLW6oyOeTKmQ-9iHFVNxQ,92
20
- dnaStreaming-2.2.0.dist-info/top_level.txt,sha256=08Lk4-qbvG3EGfiPeUI0NFUjIDJbA2RWO8ntC5friWs,13
21
- dnaStreaming-2.2.0.dist-info/RECORD,,
17
+ dnaStreaming-2.2.1.dev1.dist-info/LICENSE,sha256=l0T3WdIyACkYU-XdqJnaLC5_m1Wa0wJEZSJC4Owc7Y4,1077
18
+ dnaStreaming-2.2.1.dev1.dist-info/METADATA,sha256=gsxv7B8WaNLdIO4vGE_qM4rw1GrVtqs5DJ3q8nfc3X4,7554
19
+ dnaStreaming-2.2.1.dev1.dist-info/WHEEL,sha256=Wyh-_nZ0DJYolHNn1_hMa4lM7uDedD_RGVwbmTjyItk,91
20
+ dnaStreaming-2.2.1.dev1.dist-info/top_level.txt,sha256=08Lk4-qbvG3EGfiPeUI0NFUjIDJbA2RWO8ntC5friWs,13
21
+ dnaStreaming-2.2.1.dev1.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: bdist_wheel (0.43.0)
2
+ Generator: setuptools (71.1.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5