|
23 | 23 | from rollbar.lib import events, filters, dict_merge, parse_qs, text, transport, urljoin, iteritems, defaultJSONEncode |
24 | 24 |
|
25 | 25 |
|
26 | | -__version__ = '0.16.3' |
| 26 | +__version__ = '0.16.4beta' |
27 | 27 | __log_name__ = 'rollbar' |
28 | 28 | log = logging.getLogger(__log_name__) |
29 | 29 |
|
@@ -124,7 +124,7 @@ def wrap(*args, **kwargs): |
124 | 124 | from twisted.internet.ssl import CertificateOptions |
125 | 125 | from twisted.internet import task, defer, ssl, reactor |
126 | 126 | from zope.interface import implementer |
127 | | - |
| 127 | + |
128 | 128 | @implementer(IPolicyForHTTPS) |
129 | 129 | class VerifyHTTPS(object): |
130 | 130 | def __init__(self): |
@@ -275,7 +275,12 @@ def _get_fastapi_request(): |
275 | 275 | 'root': None, # root path to your code |
276 | 276 | 'branch': None, # git branch name |
277 | 277 | 'code_version': None, |
278 | | - 'handler': 'default', # 'blocking', 'thread' (default), 'async', 'agent', 'tornado', 'gae', 'twisted' or 'httpx' |
| 278 | + # 'blocking', 'thread' (default), 'async', 'agent', 'tornado', 'gae', 'twisted', 'httpx' or 'thread_pool' |
| 279 | + # 'async' requires Python 3.4 or higher. |
| 280 | + # 'httpx' requires Python 3.7 or higher. |
| 281 | + # 'thread_pool' requires Python 3.2 or higher. |
| 282 | + 'handler': 'default', |
| 283 | + 'thread_pool_workers': None, |
279 | 284 | 'endpoint': DEFAULT_ENDPOINT, |
280 | 285 | 'timeout': DEFAULT_TIMEOUT, |
281 | 286 | 'agent.log_file': 'log.rollbar', |
@@ -383,6 +388,9 @@ def init(access_token, environment='production', scrub_fields=None, url_fields=N |
383 | 388 |
|
384 | 389 | if SETTINGS.get('handler') == 'agent': |
385 | 390 | agent_log = _create_agent_log() |
| 391 | + elif SETTINGS.get('handler') == 'thread_pool': |
| 392 | + from rollbar.lib.thread_pool import init_pool |
| 393 | + init_pool(SETTINGS.get('thread_pool_workers', None)) |
386 | 394 |
|
387 | 395 | if not SETTINGS['locals']['safelisted_types'] and SETTINGS['locals']['whitelisted_types']: |
388 | 396 | warnings.warn('whitelisted_types deprecated use safelisted_types instead', DeprecationWarning) |
@@ -523,6 +531,7 @@ def send_payload(payload, access_token): |
523 | 531 | - 'gae': calls _send_payload_appengine() (which makes a blocking call to Google App Engine) |
524 | 532 | - 'twisted': calls _send_payload_twisted() (which makes an async HTTP request using Twisted and Treq) |
525 | 533 | - 'httpx': calls _send_payload_httpx() (which makes an async HTTP request using HTTPX) |
| 534 | + - 'thread_pool': uses a pool of worker threads to make HTTP requests off the main thread. Returns immediately. |
526 | 535 | """ |
527 | 536 | payload = events.on_payload(payload) |
528 | 537 | if payload is False: |
@@ -569,6 +578,8 @@ def send_payload(payload, access_token): |
569 | 578 | _send_payload_async(payload_str, access_token) |
570 | 579 | elif handler == 'thread': |
571 | 580 | _send_payload_thread(payload_str, access_token) |
| 581 | + elif handler == 'thread_pool': |
| 582 | + _send_payload_thread_pool(payload_str, access_token) |
572 | 583 | else: |
573 | 584 | # default to 'thread' |
574 | 585 | _send_payload_thread(payload_str, access_token) |
@@ -1510,6 +1521,18 @@ def _send_payload_thread(payload_str, access_token): |
1510 | 1521 | thread.start() |
1511 | 1522 |
|
1512 | 1523 |
|
| 1524 | +def _send_payload_pool(payload_str, access_token): |
| 1525 | + try: |
| 1526 | + _post_api('item/', payload_str, access_token=access_token) |
| 1527 | + except Exception as e: |
| 1528 | + log.exception('Exception while posting item %r', e) |
| 1529 | + |
| 1530 | + |
| 1531 | +def _send_payload_thread_pool(payload_str, access_token): |
| 1532 | + from rollbar.lib.thread_pool import submit |
| 1533 | + submit(_send_payload_pool, payload_str, access_token) |
| 1534 | + |
| 1535 | + |
1513 | 1536 | def _send_payload_appengine(payload_str, access_token): |
1514 | 1537 | try: |
1515 | 1538 | _post_api_appengine('item/', payload_str, access_token=access_token) |
|
0 commit comments