dsw-command-queue 4.1.0__tar.gz → 4.2.0__tar.gz

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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dsw-command-queue
3
- Version: 4.1.0
3
+ Version: 4.2.0
4
4
  Summary: Library for working with command queue and persistent commands
5
5
  Author-email: Marek Suchánek <marek.suchanek@ds-wizard.org>
6
6
  License: Apache License 2.0
@@ -19,7 +19,7 @@ Classifier: Topic :: Utilities
19
19
  Requires-Python: <4,>=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Requires-Dist: dsw-database==4.1.0
22
+ Requires-Dist: dsw-database==4.2.0
23
23
 
24
24
  # Data Stewardship Wizard: Command Queue
25
25
 
@@ -9,9 +9,9 @@ BuildInfo = namedtuple(
9
9
  )
10
10
 
11
11
  BUILD_INFO = BuildInfo(
12
- version='v4.1.0~6647324',
13
- built_at='2023-12-05 17:40:44Z',
14
- sha='6647324f52d8be83435ceba1cd98111ae5e814bf',
12
+ version='v4.2.0~0fd7b7f',
13
+ built_at='2024-01-02 07:46:04Z',
14
+ sha='0fd7b7f97f993e4e0f3ca92869a3c07f2286d95c',
15
15
  branch='HEAD',
16
- tag='v4.1.0',
16
+ tag='v4.2.0',
17
17
  )
@@ -4,6 +4,8 @@ import logging
4
4
  import os
5
5
  import platform
6
6
  import psycopg
7
+ import psycopg.generators
8
+ import select
7
9
  import signal
8
10
  import tenacity
9
11
 
@@ -50,13 +52,14 @@ class CommandWorker:
50
52
  class CommandQueue:
51
53
 
52
54
  def __init__(self, worker: CommandWorker, db: Database,
53
- channel: str, component: str):
55
+ channel: str, component: str, timeout: float):
54
56
  self.worker = worker
55
57
  self.db = db
56
58
  self.queries = CommandQueries(
57
59
  channel=channel,
58
60
  component=component
59
61
  )
62
+ self.timeout = timeout
60
63
 
61
64
  @tenacity.retry(
62
65
  reraise=True,
@@ -76,19 +79,29 @@ class CommandQueue:
76
79
  )
77
80
  queue_conn.listening = True
78
81
  LOG.info('Listening for jobs in command queue')
79
- running = True
80
- while running:
81
- queue_notifications = queue_conn.connection.notifies()
82
- LOG.info('Entering working cycle, waiting for notifications')
83
- for notification in queue_notifications:
84
- LOG.info(f'Notification received: {notification}')
85
- while self.accept_notification(payload=notification):
86
- pass
87
-
88
- if INTERRUPTED:
89
- LOG.debug('Interrupt signal received, ending...')
90
- queue_notifications.close()
91
- running = False
82
+ fds = [queue_conn.connection.pgconn.socket]
83
+ if IS_LINUX:
84
+ fds.append(_QUEUE_PIPE_R)
85
+ LOG.info('Entering working cycle, waiting for notifications')
86
+ while True:
87
+ res = True
88
+ while res:
89
+ res = self.fetch_and_process()
90
+ w = select.select(fds, [], [], self.timeout)
91
+
92
+ if INTERRUPTED:
93
+ LOG.debug('Interrupt signal received, ending...')
94
+ break
95
+
96
+ if w == ([], [], []):
97
+ LOG.debug(f'Nothing received in this cycle '
98
+ f'(timeouted after {self.timeout} seconds).')
99
+ else:
100
+ notifications = 0
101
+ for n in psycopg.generators.notifies(queue_conn.connection.pgconn):
102
+ notifications += 1
103
+ LOG.debug(str(n))
104
+ LOG.info(f'Notifications received ({notifications})')
92
105
  LOG.debug('Exiting command queue')
93
106
 
94
107
  def accept_notification(self, payload: psycopg.Notify) -> bool:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: dsw-command-queue
3
- Version: 4.1.0
3
+ Version: 4.2.0
4
4
  Summary: Library for working with command queue and persistent commands
5
5
  Author-email: Marek Suchánek <marek.suchanek@ds-wizard.org>
6
6
  License: Apache License 2.0
@@ -19,7 +19,7 @@ Classifier: Topic :: Utilities
19
19
  Requires-Python: <4,>=3.10
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
- Requires-Dist: dsw-database==4.1.0
22
+ Requires-Dist: dsw-database==4.2.0
23
23
 
24
24
  # Data Stewardship Wizard: Command Queue
25
25
 
@@ -0,0 +1 @@
1
+ dsw-database==4.2.0
@@ -4,7 +4,7 @@ build-backend = 'setuptools.build_meta'
4
4
 
5
5
  [project]
6
6
  name = 'dsw-command-queue'
7
- version = "4.1.0"
7
+ version = "4.2.0"
8
8
  description = 'Library for working with command queue and persistent commands'
9
9
  readme = 'README.md'
10
10
  keywords = ['dsw', 'subscriber', 'publisher', 'database', 'queue', 'processing']
@@ -25,7 +25,7 @@ classifiers = [
25
25
  requires-python = '>=3.10, <4'
26
26
  dependencies = [
27
27
  # DSW
28
- "dsw-database==4.1.0",
28
+ "dsw-database==4.2.0",
29
29
  ]
30
30
 
31
31
  [project.urls]
@@ -1 +0,0 @@
1
- dsw-database==4.1.0