beanqueue 0.2.1__tar.gz → 0.2.3__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.
Files changed (28) hide show
  1. {beanqueue-0.2.1 → beanqueue-0.2.3}/PKG-INFO +1 -1
  2. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/app.py +23 -1
  3. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/config.py +3 -0
  4. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/events.py +2 -0
  5. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/models/task.py +2 -0
  6. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/models/worker.py +0 -2
  7. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/processors/processor.py +2 -0
  8. {beanqueue-0.2.1 → beanqueue-0.2.3}/pyproject.toml +1 -1
  9. {beanqueue-0.2.1 → beanqueue-0.2.3}/LICENSE +0 -0
  10. {beanqueue-0.2.1 → beanqueue-0.2.3}/README.md +0 -0
  11. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/__init__.py +0 -0
  12. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/cmds/__init__.py +0 -0
  13. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/cmds/create_tables.py +0 -0
  14. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/cmds/process.py +0 -0
  15. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/cmds/submit.py +0 -0
  16. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/cmds/utils.py +0 -0
  17. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/constants.py +0 -0
  18. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/db/__init__.py +0 -0
  19. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/db/base.py +0 -0
  20. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/db/session.py +0 -0
  21. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/models/__init__.py +0 -0
  22. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/models/helpers.py +0 -0
  23. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/processors/__init__.py +0 -0
  24. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/processors/registry.py +0 -0
  25. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/services/__init__.py +0 -0
  26. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/services/dispatch.py +0 -0
  27. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/services/worker.py +0 -0
  28. {beanqueue-0.2.1 → beanqueue-0.2.3}/bq/utils.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: beanqueue
3
- Version: 0.2.1
3
+ Version: 0.2.3
4
4
  Summary: BeanQueue or BQ for short, PostgreSQL SKIP LOCK based worker queue library
5
5
  License: MIT
6
6
  Author: Fang-Pen Lin
@@ -8,6 +8,7 @@ import threading
8
8
  import time
9
9
  import typing
10
10
  from wsgiref.simple_server import make_server
11
+ from wsgiref.simple_server import WSGIRequestHandler
11
12
 
12
13
  import venusian
13
14
  from sqlalchemy import func
@@ -31,6 +32,21 @@ from .utils import load_module_var
31
32
  logger = logging.getLogger(__name__)
32
33
 
33
34
 
35
+ class WSGIRequestHandlerWithLogger(WSGIRequestHandler):
36
+ logger = logging.getLogger("metrics_server")
37
+
38
+ def log_message(self, format, *args):
39
+ message = format % args
40
+ self.logger.info(
41
+ "%s - - [%s] %s\n"
42
+ % (
43
+ self.address_string(),
44
+ self.log_date_time_string(),
45
+ message.translate(self._control_char_table),
46
+ )
47
+ )
48
+
49
+
34
50
  class BeanQueue:
35
51
  def __init__(
36
52
  self,
@@ -213,7 +229,10 @@ class BeanQueue:
213
229
  host = self.config.METRICS_HTTP_SERVER_INTERFACE
214
230
  port = self.config.METRICS_HTTP_SERVER_PORT
215
231
  with make_server(
216
- host, port, functools.partial(self._serve_http_request, worker_id)
232
+ host,
233
+ port,
234
+ functools.partial(self._serve_http_request, worker_id),
235
+ handler_class=WSGIRequestHandlerWithLogger,
217
236
  ) as httpd:
218
237
  logger.info("Run metrics HTTP server on %s:%s", host, port)
219
238
  httpd.serve_forever()
@@ -255,6 +274,9 @@ class BeanQueue:
255
274
 
256
275
  metrics_server_thread = None
257
276
  if self.config.METRICS_HTTP_SERVER_ENABLED:
277
+ WSGIRequestHandlerWithLogger.logger.setLevel(
278
+ self.config.METRICS_HTTP_SERVER_LOG_LEVEL
279
+ )
258
280
  metrics_server_thread = threading.Thread(
259
281
  target=self.run_metrics_http_server,
260
282
  args=(worker.id,),
@@ -39,6 +39,9 @@ class Config(BaseSettings):
39
39
  # the metrics http server port to listen
40
40
  METRICS_HTTP_SERVER_PORT: int = 8000
41
41
 
42
+ # default log level for metrics http server
43
+ METRICS_HTTP_SERVER_LOG_LEVEL: int = 30
44
+
42
45
  POSTGRES_SERVER: str = "localhost"
43
46
  POSTGRES_USER: str = "bq"
44
47
  POSTGRES_PASSWORD: str = ""
@@ -1,3 +1,5 @@
1
1
  import blinker
2
2
 
3
3
  worker_init = blinker.signal("worker-init")
4
+
5
+ task_failure = blinker.signal("task-failure")
@@ -85,6 +85,8 @@ class Task(TaskModelMixin, TaskModelRefWorkerMixin, Base):
85
85
  ("id", self.id),
86
86
  ("state", self.state),
87
87
  ("channel", self.channel),
88
+ ("module", self.module),
89
+ ("func_name", self.func_name),
88
90
  ]
89
91
  return f"<{self.__class__.__name__} {make_repr_attrs(items)}>"
90
92
 
@@ -2,7 +2,6 @@ import datetime
2
2
  import enum
3
3
  import uuid
4
4
 
5
- from sqlalchemy import Column
6
5
  from sqlalchemy import DateTime
7
6
  from sqlalchemy import Enum
8
7
  from sqlalchemy import func
@@ -12,7 +11,6 @@ from sqlalchemy.dialects.postgresql import UUID
12
11
  from sqlalchemy.orm import declared_attr
13
12
  from sqlalchemy.orm import Mapped
14
13
  from sqlalchemy.orm import mapped_column
15
- from sqlalchemy.orm import Mapper
16
14
  from sqlalchemy.orm import relationship
17
15
 
18
16
  from ..db.base import Base
@@ -5,6 +5,7 @@ import typing
5
5
 
6
6
  from sqlalchemy.orm import object_session
7
7
 
8
+ from .. import events
8
9
  from .. import models
9
10
 
10
11
  logger = logging.getLogger(__name__)
@@ -36,6 +37,7 @@ class Processor:
36
37
  result = self.func(**base_kwargs, **task.kwargs)
37
38
  except Exception as exc:
38
39
  logger.error("Unhandled exception for task %s", task.id, exc_info=True)
40
+ events.task_failure.send(self, task=task, exception=exc)
39
41
  if self.auto_rollback_on_exc:
40
42
  savepoint.rollback()
41
43
  # TODO: add error event
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "beanqueue"
3
- version = "0.2.1"
3
+ version = "0.2.3"
4
4
  description = "BeanQueue or BQ for short, PostgreSQL SKIP LOCK based worker queue library"
5
5
  authors = ["Fang-Pen Lin <fangpen@launchplatform.com>"]
6
6
  license = "MIT"
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes