Commit Graph

211 Commits

Author SHA1 Message Date
Jonas Miederer b3e89101dc
Upgrade Azure Storage Queues transport to version 12 (#1539)
* updated azurestoragequeues transport for azure-storage-queues v12 + added basic tests

* fixed flake8 issues

* pinned azure-storage-queue lib to >= v12.0.0

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* azure-storage-queue>=12.2.0

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2022-04-23 14:15:49 +06:00
Marcelo Trylesinski 14d395aa85
Annotate `exceptions.py` and `clocks.py` (#1526)
* Annotate `exceptions.py`

* Annotate `clocks.py`
2022-04-18 18:52:26 +06:00
Jakub Pieńkowski 661d92222e
Support pymongo 4.x (#1536)
* Support pymongo 4.x

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix problems detected by CI

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-18 18:10:38 +06:00
Marcelo Trylesinski 7516daf7a7 Bump pyupgrade version and add __future__.annotations import 2022-04-15 14:16:57 +06:00
Sondre Lillebø Gundersen 87384a91c6 chore: Update `__exit__` signatures
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-04-12 20:41:29 +06:00
Marcelo Trylesinski 7d99b6f79f
Annotate `utils/uuid.py` and `utils/text.py` (#1514)
* Annotate `utils/uuid.py` and `utils/text.py`

* Use callable without any parameter

* Update kombu/utils/text.py
2022-04-12 20:39:42 +06:00
dobosevych 894ddfc8b6
Added possibility to serialize and deserialize binary messages in json (#1516)
* Added possibility to serialize and deserialize binary messages in json

* Flake8 fixed

* Hypothesis added to improve test range. Fixed issue b'\x80' serialization.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Added docstring

* Fixed pylint

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-04-12 18:52:41 +06:00
Oliver Nemček aab2588c4a
Protect set of ready tasks by lock to avoid concurrent updates. (#1489)
When there is no locking then there is a possibility that multiple threads
manipulate with the same object at the same time.
The issue is manifested as:
```
RuntimeError: Set changed size during iteration
```

See: https://github.com/celery/celery/issues/7162
2022-03-24 16:49:17 +02:00
Gao 0282e1419f
Add fanout to filesystem (#1499)
* Create a folder for each queue when using filesystem transport and add fanout support

* clean up unused variables

* Add fanout support to filesystem transport

filesystem transport lacks of fanout support.

1. Add fanout support to filesystem transport.
2. Add a unit test for it.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove the refactoring work and make the test passed

1. Remove all of refactoring work
2. make the test pass

* Use pathlib for some Path operation

* Some reviewed changes

Co-authored-by: Yuriy Halytskyy <y.halytskyy@auckland.ac.nz>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-03-15 20:21:07 +06:00
Shane Hathaway 9b505f4297 Add an option to not base64-encode SQS messages.
Also simplify the base64 decoding logic so that we don't have to
run base64 decoding twice for every message.
2022-03-04 11:47:01 +06:00
vinay karanam 3475986ee0
Added global_keyprefix support for pubsub clients (#1495)
* Added global_keyprefix support for pubsub clients

* Added test cases
2022-02-28 16:48:09 +06:00
Michael Manganiello 2f3b153acc
Warn about missing hostname only when default one is available (#1488)
* Warn about missing hostname only when default one is available

The `No hostname was supplied` warning is affecting projects that use
AWS SQS (as detailed in #1357), as a hostname is not required when
setting up the broker URL. Instead, the official documentation [0] specifies
that the valid broker URL formats are:

* `sqs://`
* `sqs://aws_access_key_id:aws_secret_access_key@`

With these formats, the `kombu.utils.url.parse_url` util doesn't return
a hostname, and workers end up triggering the following warning:

> No hostname was supplied. Reverting to default 'None'

As the SQS transport doesn't provide a default value for hostname, this
diff changes the behavior to only warn the user when the hostname hasn't
been supplied but a default one is being set by the default connection
parameters for the defined transport.

Fixes #1357.

[0] https://docs.celeryproject.org/en/stable/getting-started/backends-and-brokers/sqs.html#configuration

* Use caplog default logging level of WARNING
2022-02-02 19:23:14 +06:00
Mads Jensen ac92e047c1
Remove use of OrderedDict in various places (#1483)
* Remove use of OrderedDict in Connection.info.

* Remove remnant use of collections.OrderedDict

* Undo QoS._delivered move to Python standard dictionary.

This requires more work to convert, due to a hack in how the dictionary
is used.

* Undo LRUCache.data to dict conversion.

It's also problematic, and caused tests to fail.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Revert QoS._delivered comment chagne.

* Update comment

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2022-01-30 19:46:45 +06:00
Mads Jensen 31a84d5b3d
Some small updates (#1486)
* Some small updates

* Update QpidException super-call to Python 3 syntax.
2022-01-30 18:34:54 +06:00
Denis Kubashevskiy 3ec6dc0fd1
Set redelivered property for Celery with Redis (#1484)
* Set redelivered property for Celery with Redis

Fixed setting `redelivered` value for Celery when Redis broker is used.

* Add `test_do_restore_message_celery` test

* Fix long line
2022-01-28 20:16:22 +06:00
John Koehl a7355ac442
Fix issue #789: Async http code not allowing for proxy config (#790)
* (Issue #789) Don't reset the proxy config in the async curl based http request building unless that is specified by the caller

* Test curl proxy only set when explicitly specified by caller

Co-authored-by: Adam Aljets <aljets@users.noreply.github.com>
2022-01-14 09:37:46 +06:00
Paul Brown 9c062bdca5
allow getting recoverable_connection_errors without an active transport (#1471)
* allow getting recoverable_connection_errors without an active transport

* move redis transport errors to class

* move consul transport errors to class

* move etcd transport errors to class

* remove redis.Transport._get_errors and references in tests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* fix flake8 errors

* add integration test for redis ConnectionError

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-30 12:28:11 +06:00
Paul Brown 81ec90fbce
prevent redis event loop stopping on 'consumer: Cannot connect' (#1477)
* prevent redis event loop stopping on 'consumer: Cannot connect'

* fix flake8 errors

* simplify event pool polling started check
2021-12-25 10:24:08 +06:00
Mehdi Pourfar a9c4f9837c
respect connection timeout (#1458)
* pass timeout to ensure connection function

* test connection respect its timeout
2021-12-24 15:21:44 +06:00
Paul Brown 47781af050 prevent event loop polling on closed redis transports (and causing leak) 2021-12-24 09:25:47 +06:00
Paul Brown 507b306400
reduce memory usage of Transport (#1470)
* reduce memory usage of Transport

* fix flake8 errors

* move channel_id login into _get_free_channel_id
2021-12-23 20:41:30 +06:00
Matus Valo 58975b2a95
Ensure that restore is atomic in redis transport (#1444)
* Ensure that restore is atomic in redis transport

* Fix wrong variable

* Added integration tests

* Update unittests

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix integration tests

* Fix flake8

* Fix queue name in int. tests

* Cosmetic clean up of integration tests

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-12-10 23:53:40 +01:00
n0061q 081e9e6cff
SQS transport: detect FIFO queue properly by checking queue URL (#1450)
* SQS: detect FIFO queue properly

* SQS: validate predefined queues

Co-authored-by: Yaroslav Litus <Yaroslav.Litus@F-Secure.com>
2021-12-03 09:46:41 +01:00
Matus Valo 73b10a9346 Return empty list instead of InconsistencyError when exchange table is empty
Missing redis key containg set of queues bound to queue is caused
by removal all queues from the exchange. Hence, we should not raise an
exception but just return empty list of queues instead. This commit
fixes e.g. case publishing message against empty exchange:

import kombu
conn = kombu.Connection('redis://')
exchange = kombu.Exchange('name', type='direct')
exchange.declare(channel=conn.default_channel)

producer = conn.Producer()
producer.publish(
     {'hello': 'world'},
     exchange=exchange,
     routing_key='queue1'
)

But it also fixes the case when last queue is unbound from exchange and
after publishing to this exchange:

import kombu
conn = kombu.Connection('redis://')
exchange = kombu.Exchange('name', type='direct')
queue1 = kombu.Queue('queue1', exchange=exchange, routing_key='queue1')
exchange.declare(channel=conn.default_channel)
queue1 = queue1.bind(channel=conn.default_channel)
queue1.declare()

producer = conn.Producer()
producer.publish(
     {'hello': 'world'},
     exchange=exchange,
     routing_key='queue1'
)

queue1.delete()

producer.publish(
     {'hello': 'world'},
     exchange=exchange,
     routing_key='queue1'
)
2021-10-25 07:28:10 +06:00
Matus Valo 0253cfb7b2
Fix test_pidbox unittests to support non-linux platforms (#1398) 2021-10-05 22:37:59 +02:00
Matus Valo 4e8f217526
fix flake8 in kombu/asynchronous/aws/connection.py (#1397)
* fix flake8 in kombu/asynchronous/aws/connection.py

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-10-05 18:08:07 +06:00
Matus Valo 28c8984e7d Added unittests for #1394 2021-10-05 14:02:47 +02:00
pre-commit-ci[bot] ee99595232
[pre-commit.ci] pre-commit autoupdate (#1393)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/asottile/pyupgrade: v2.26.0 → v2.28.0](https://github.com/asottile/pyupgrade/compare/v2.26.0...v2.28.0)

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-09-27 21:35:17 +03:00
kaiix 580b5219cc Fix: check redis response type 2021-09-16 20:50:28 +06:00
Matus Valo 07bab02bc3
Remove dependency to case (#1389)
* Remove dependency to case

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Fix flake8 errors

* Remove unused code

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-09-15 21:00:08 +06:00
Matus Valo ef6ec99154 Use ANY from unittest instead of case.mock 2021-09-12 01:03:09 +02:00
Matus Valo 7230665e5c Make BrokerState Transport specific 2021-08-30 14:02:20 +06:00
Gábor Boros 24b0820d0b fix: add missing commands to prefix
Add missing DEL, RPUSH, RPOP and SREM commands to the list of commands to prefix.

Also, this commit refactors the prefixing logic a bit to make it simpler.
2021-08-27 16:35:35 +06:00
Gábor Boros 39584a1940
Add global key prefix for keys set by Redis transporter (#1349)
* Introduce global key prefix for redis transport

Co-authored-by: Matus Valo <matusvalo@users.noreply.github.com>

* refactor: use a custom redis client

As per the suggestions, refactor the redis key prefixing to use a custom
redis client that prefixes the keys it uses.

The custom client implementation does not prefix every key by default as
the way of prefixing keys may differ for some redis commands, instead it
lists those keys that will be prefixed. In case of commands, where
multiple keys can be passed as an argument, the custom client defines
where the arg positions are starting and ending for the given command.

* test: fix unit tests by moving import statement

* fix: wrap redis.parse_response to remove key prefixes

Co-authored-by: Matus Valo <matusvalo@users.noreply.github.com>

* fix: typo

* fix: lint

Co-authored-by: Antonin Delpeuch <antonin@delpeuch.eu>
Co-authored-by: Matus Valo <matusvalo@users.noreply.github.com>
Co-authored-by: Jillian Vogel <jill@opencraft.com>
2021-08-25 14:08:17 +02:00
Brad Smith 9a91e8b780 SQS Channel.predefined_queues should be `{}` if not defined
Previously, calling `reject` when `predefined_queues` was not configured would cause `AttributeError` to be raised from `_extract_backoff_policy_configuration_and_message`. That exception could crash the whole Celery worker and force it to exit early because `AttributeError` is not excepted in the nearby call stack.
2021-08-21 16:22:41 +06:00
pre-commit-ci[bot] 1a512ffac9 [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2021-08-05 20:05:25 +06:00
Matus Valo c0f2b847f0 Use hostname from URI when server_host is None 2021-08-05 20:05:25 +06:00
Thomas Grainger 241b5dcff8
enable pre-commit (#1355)
* enable pre-commit

* use extend-ignore for flake8

* manual flake8 fixes

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Update kombu/__init__.py

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2021-07-20 19:07:49 +06:00
Gábor Boros 2d036f54b6
Add support for setting redis username (#1351)
* feat: add support for setting redis username

* tests: add redis connparams credentials tests
2021-07-08 23:27:05 +02:00
Felix Yan e5dbfed8ae
Move pytest.importorskip to run earlier (#1346)
* Move pytest.importorskip to run earlier

Currently pytest fails to collect tests when `azure` is not present. Moving the pytest.importorskip clause before `from kombu.transport import azureservicebus` fixes it.

```
==================================== ERRORS ====================================
__________ ERROR collecting t/unit/transport/test_azureservicebus.py ___________
ImportError while importing test module '/build/python-kombu/src/kombu-5.1.0/t/unit/transport/test_azureservicebus.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/usr/lib/python3.9/importlib/__init__.py:127: in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
t/unit/transport/test_azureservicebus.py:12: in <module>
    from kombu.transport import azureservicebus
kombu/transport/azureservicebus.py:66: in <module>
    import azure.core.exceptions
E   ModuleNotFoundError: No module named 'azure'
```

* Add # noqa to make linter happy
2021-06-11 09:21:09 +02:00
Matus Valo 4cf1a21712
prepare_accept_content() now raises SerializerNotInstalled instead of KeyError (#1343)
* Fix broken nested() after #1320

* prepare_accept_content now raises SerializerNotInstalled when wrong serializer alias is passed
2021-05-23 12:09:06 +06:00
Luis Saavedra e6d76d13fc
add accept parameter to SimpleQueue class (#1140)
* add accept parameter to SimpleQueue class

* Fixed missing accept for get_nowait() and added unittests

* Remove unused **kwargs from SimpleQueue.__init__

* Use self.consumer.accept instead of new attribute in SimpleQueue

* Add tests for simple interface when accept=[]

Co-authored-by: Matus Valo <matusvalo@gmail.com>
2021-05-22 21:28:05 +02:00
Matus Valo a920bb0365
Revert "chore: Refactor code quality issues (#1320)" (#1342)
This reverts commit 3b6cd13d3b.
2021-05-19 14:05:14 +02:00
Aksh Gupta 3b6cd13d3b
chore: Refactor code quality issues (#1320)
* chore: refactor code quality issues

* remove .deepsource.toml config file
2021-04-28 18:40:37 +03:00
Matus Valo c35fd1d9b4
Make flake8 and pydocstyle happy (#1333)
* Make flake8 happy

* Make pydocstyle happy
2021-04-13 23:20:31 +02:00
Tomasz Niedziela-Brach 44dcc33a74
Azure Service Bus - versatile queue names fix (#1324)
* fixed character replace table according to the comment above - dots replaced by dashes, other punctuations replaced by underscores

* optimised with precalculated punctuation set - according to @thedrow suggestion

* queue name tests

* cleanup
2021-04-04 18:02:03 +03:00
Omer Katz 560518287a
Use a thread-safe implementation of cached_property (#1316)
* Use a thread-safe implementation of cached_property.

* Restore setter and deleter.

* Restore tests.

* Fix __get__ signature for backport.

* Cleanup.

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2021-04-01 13:48:00 +03:00
gal cohen b5a1edde48
SQS Broker - handle STS authentication with AWS (#1322)
* handle sqs sts

* add doc

* use string format

* improve docs

* Update kombu/transport/SQS.py

Co-authored-by: Omer Katz <omer.drow@gmail.com>

* add helper method and tests

* changer to private

Co-authored-by: galcohen <gal.cohen@autodesk.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Omer Katz <omer.drow@gmail.com>
2021-03-29 11:35:49 +03:00
Omer Katz 1e20625d7b Drop support for the lzma backport. 2021-03-16 10:02:55 +06:00
Max Nikitenko 2a704e3585
fix: non kombu json message decoding in SQS transport (#1306)
* fix: non kombu json message decoding in SQS transport

* fix: non kombu json message decoding in SQS transport - add tests

Co-authored-by: Max Nikitenko <max.nikitenko@namecheap.com>
2021-03-07 14:35:55 +06:00