Commit Graph

307 Commits

Author SHA1 Message Date
Omer Katz 087527f209
Added confirm_timeout argument. (#2167) 2024-10-26 19:25:25 +03:00
Omer Katz 1686c35a06
Apply retry policy to maybe_declare(). (#2174) 2024-10-24 19:15:15 +03:00
Roman Inflianskas c48be8800d
Add support for Python 3.13 (#2052)
Fixes https://github.com/celery/kombu/issues/2051.
2024-10-23 22:47:49 +03:00
Haim Daniel e5ea1f6d58
Fix: restrict google protobuf version (#2175)
- protobuf version in versions larger than 4.25.5 when used by google-cloud-pubsub
  raises the following error:

site-packages/google/protobuf/internal/well_known_types.py", line 443, in FromTimedelta
    raise AttributeError(
AttributeError: Fail to convert to Duration.
Expected a timedelta like object got str: 'str' object has no attribute 'seconds'

  Fix this by restriction of the allowed package versions
- Added unit test to validate pubsub and protobuf compatibility
- Enabled google-cloud-pubsub package versions bump

Co-authored-by: Haim Daniel <haimdaniel@gmail.com>
2024-10-23 19:22:34 +03:00
Omer Katz 7e4f1bbecc
Fix regression from #2148 (#2165)
* Fix regression from #2148.

Fixes #2157.

* Fix linter error.
2024-10-21 15:22:45 +06:00
Omer Katz 2a206a12c4
Added a unit test that proves timeout is used when retry policy is specified. (#2166) 2024-10-20 20:23:29 +03:00
Paul Rysiavets 07c8852be5
Feature: urllib3 instead of curl (#2134)
* feature(urllib3): add urllib3 client

* test(urllib3): test urllib3 client

* test(urllib3): update http test for urllib3

* test(urllib3): use urllib3 client instead of curl

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

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

* style(urllib3): remove unused imports

* style(urllib3): fix pre-commit errors

* ci(urllib3): remove pycurl dependency

* docs(urllib3): add docs

* style(urllib3): fix failing gh-workflow py3.8

* style(urllib3): add mention of ProxyManager

* style(urllib3): fix pre-commit issues

* style(pycurl): remove curl-related code

* feat(urllib3): add missing request features (header, auth, ssl, proxy, redirects)

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

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

* fix(urllib3): improve styling

* test(urllib3): add new tests

* fix(urllib3): fix request auth

* fix(aws): validate certificate on request

* style(): add missing exports

* feat(aws): add ssl certificate verification from boto

* feat(urllib): try to use certifi.where() if request.ca_certs are not provided

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

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

* ci(pydocstyle): add missing docstring in public class

* test(urllib3): improve test case

* ci(pydocstyle): fix multi-line docstring summary should start at the first line

* feat(urllib3): remove assert_hostname

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

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

* test(boto): add test for get_cert_path returning .pem file path

* test(urllib3): add test for _get_pool_key_parts method

* [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>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
Co-authored-by: Tomer Nosrati <tomer.nosrati@gmail.com>
2024-10-14 17:01:25 +06:00
Omer Katz 3f5d19973e
Update the transport options according to the retry policy (#2148)
* Update the transport options according to the retry policy.

* Add unit test.
2024-10-13 20:11:22 +03:00
Haim Daniel 2f58823312
Add support for Google Pub/Sub as transport broker (#2147)
* Add support for Google Pub/Sub as transport broker

 * Add tests
 * Add docs

* flake8

* flake8

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

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

* Fix future import

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

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

* Add missing test requirements

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

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

* Add monitoring dependency

* Fix test for python3.8

* Mock better google's monitoring api

* Flake8

* Add refdoc

* Add extra url to workaround pypy grpcio

* Add extra index url in tox for grpcio/pypy support

* Revert "Add extra url to workaround pypy grpcio"

This reverts commit dfde4d523c.

* pin grpcio version to match extra_index wheel

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

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

* Reduce poll calls if qos denies msg rx

---------

Co-authored-by: Haim Daniel <haimdaniel@gmail.com>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tomer Nosrati <tomer.nosrati@gmail.com>
2024-10-13 16:49:55 +03:00
Omer Katz 5a88a28f31
Add native delayed delivery API to kombu (#2128)
* Adjust flake8 configuration to match Celery's configuration.

* Add native delayed delivery API.

* Add documentation.

* Fix linter errors.

* Fix pydocstyle errors.

* Fix apicheck linter.

* Address code review.
2024-10-12 21:17:55 +03:00
Omer Katz 72c0b8d992
Apply errback and callback when retry occurs (#2129)
* Apply errback and callback when retry occurs.

* Added unit tests.
2024-10-03 13:37:03 +03:00
Paul Rysiavets ea6a160f6b
fix(pytest): skip file-lock test on Windows (#2138) 2024-10-02 13:26:17 +03:00
Tomer Nosrati b48d1cbab0
Improve pre-commit checks and fix all new lint errors (#2124)
* Added pyproject.toml

* Imported .pre-commit-config.yaml config from Celery

* Codespell Fixes

* Fixed lint errors

* Added back autoflake
2024-09-25 22:34:56 +03:00
FrankK-1234 33490adf9c Revert: allow users to disable broker heartbeats by not providing a timeout (#2097, #2016) 2024-09-05 20:47:59 +06:00
Ashkan Ranjbar f3ccc312f9
Resolving TypeError, during version unpacking (#2098)
* - This will make sure that the version unpacking doesn't stop connection to some versions of message brokers.

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

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

* - I updated the test in this version
- Improved my code

* - Removed `merge-conflict` comments in the code!

* - linting problem resolved.

* - Docstrings are now in accordance with `pydocstyle`.

* - resolving `"_unpack_version" has incompatible type "int"` problem in `_unpack_version` method
- `"` are sent back to `'` (apparently my company's formatter `black` is not compatible with `pydocstyle`, and mine integration with VSCode has messed with kombu's repository)

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-08-25 10:12:28 +03:00
Iván Martín Vedriel a62e613da3
SQS: Fixes #2091 queue_delete() method doesn't actually delete the queue (#2099)
* SQS: wrap logic to resolve queue URL into a reusable method

* Create new `_resolve_queue_url` method for reusability.

`_new_queue` method retrieves the queue URL from cache
or fetches it from SQS, updating the cache if necessary.

`_delete` method needs to resolve the queue URL in order to
delete the queue from SQS (next commit).

Both methods will be able to reuse the same functionality by
calling the `_resolve_queue_url` method.

* Introduce DoesNotExistQueueException for easier error handling.

`_new_queue` method is responsible for creating a new queue when
 it doesn't exist, utilizing the new exception for clarity.

* Unit test coverage for `_resolve_queue_url` method.

* SQS: Fix missing queue deletion in Channel._delete

* Add call to `delete_queue` using sqs client.

`_delete` method is expected to delete the specified queue when
called. Previously, this functionality was missing, which has
now been corrected.

The method raises a `DoesNotExistQueueException` if the specified
queue name doesn’t exist.

* Update unit tests with new assertion and mock to verify queue deletion.

* [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>
2024-08-25 09:45:25 +03:00
Aviram Hassan aeebd065a6
SQS: add support for passing MessageAttributes (#2059)
* SQS: add support for passing MessageAttributes

* tests,docs

* fix tests

* format ,docs

---------

Co-authored-by: Tomer Nosrati <tomer.nosrati@gmail.com>
2024-07-21 22:52:50 +03:00
Tomer Nosrati 35a5f0a6cf
Fixed flaky integration test: test_publish_requeue_consume() (#2048) 2024-07-01 18:25:31 +03:00
Joseph Zemek d620132ece
Redis transport - Redelivered messages should respect the original priority (#2026)
* Redelivered messages should respect the original priority

* update restore message test to check priority

* flake8

* add integration tests

* also add integration test for mongodb

* flake8

* temporarily removing python 3.9 from CI due to unrelated failures

* Update .github/workflows/ci.yaml

---------

Co-authored-by: Tomer Nosrati <tomer.nosrati@gmail.com>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2024-06-25 22:15:39 +06:00
awmackowiak dcb43be891
Fix Redis connections after reconnect - consumer starts consuming the tasks after crash. (#2007)
* Add more logs

* Launch _on_connection_disconnect in Conection only if channel was added properly to the poller

* Prepare test which check the flow of the channel removal from poller

* Change the comment
2024-06-12 22:00:22 +06:00
FrankK-1234 1217865d40
ConnectionPool can't be used after .resize(..., reset=True) (resolves #2018) (#2024)
* ConnectionPool can't be used after .resize(..., reset=True) (resolves #2018)

* Update kombu/resource.py

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2024-06-11 22:43:13 +03:00
FrankK-1234 30db054e57 fix flake-err: allow uses to disable broker heartbeats by not providing a timeout 2024-06-01 10:21:46 +06:00
FrankK-1234 83ad62072d enhance: allow uses to disable broker heartbeats by not providing a timeout (#1997,#1998) 2024-06-01 10:21:46 +06:00
FrankK-1234 aec8faf034 enable/fix test_etcd.py 2024-05-18 13:28:50 +06:00
huyenvu2101 4d281948f2 Fix: Fanout exchange messages mixed across virtual databases in Redis sentinel 2024-05-04 12:28:13 +06:00
Ville Lindholm 25d02e6e1d
add escape hatch for custom JSON serialization (#1955)
* add escape hatch for custom JSON serialization

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

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

* fix lint

* fix pydocstyle

* fix whitespace

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Tomer Nosrati <tomer.nosrati@gmail.com>
Co-authored-by: Ville Lindholm <ville@lindholm.dev>
2024-03-13 13:52:42 +02:00
Julien Cosmao bda9a2f18e
Expose cancel callback from py-amqp channel.basic_consume (#1953)
When broker send Basic.cancel notification, py-amqp default behavior is
to raise a ConsumerCancelled exception. It is then treated as an error
even if connection and channel are still operationnal and connection
is closed.

Basic.cancel may be sent by broker when a queue is deleted or when
replicated queue leader change. py-amqp channel.basic_consume allow to
define a callback function on this event. It may be useful to register
this callback from kombu when consuming from a queue.

(cherry picked from commit e1fa168ace)
Signed-off-by: julien.cosmao <julien.cosmao@ovhcloud.com>

Co-authored-by: julien.cosmao <julien.cosmao@ovhcloud.com>
2024-03-09 10:23:22 +02:00
Christian Clauss 10f5c3fdd6
Upgrade to pytest v8 that remove nose compatibility (#1914) 2024-02-05 16:56:13 +02:00
ainscore 48f38779da
Always convert azureservicebus namespace to fully qualified (#1892)
* Always convert azureservicebus namespace to fully qualified

* Fix tests

* Format exception
2024-01-25 15:06:49 +01:00
Adam Sussman 159e9df430
Fix crash when using global_keyprefix with a sentinel connection (#1838)
* Fix partial closure error when instantiating redis pool for a global_keyprefix sentinel connection

* add tests for redis sentinel connection with global_keyprefix setting

* StrictRedis is deprecated, use Redis class

* add some resource cleanup

* add some resource cleanup
2024-01-09 09:28:22 +01:00
marnikow 0dec03da18
azure service bus: fix TypeError when using Managed Identities (#1825)
* azure servicebus: fix TypeError: argument of type 'DefaultAzureCredential' is not iterable

* Update t/unit/transport/test_azureservicebus.py

* Update t/unit/transport/test_azureservicebus.py

* Update t/unit/transport/test_azureservicebus.py

---------

Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2023-12-29 10:15:35 +01:00
Alisson Claudino 8aff4e73cd
fix: freeze set during ticks iter in async hub (#1830)
* test: ticks set size changed during iteration in async hub

* fix: freeze set during ticks iter in async hub
2023-12-19 13:07:56 +02:00
Rafid K 6121539379
Use the correct protocol for SQS requests (#1807)
* Use the correct protocol for SQS requests

TL;DR - The use of boto3 in #1759 resulted in relying on blocking
(synchronous) HTTP requests, which caused the performance issue reported
in #1783.

`kombu` previously used to craft AWS requests manually as explained in
detail in #1726, which resulted in an outage when botocore temporarily
changed the default protocol to JSON (before rolling back due to the
impact on celery and airflow.) To fix the issue, I submitted #1759,
which changes `kombu` to use `boto3` instead of manually crafting AWS
requests. This way when boto3 changes the default protocol, kombu won't
be impacted.

While working on #1759, I did extensive debugging to understand the
multi-threading nature of kombu. What I discovered is that there isn't
an actual multi-threading in the true sense of the word, but an event
loop that runs on the same thread and process and orchestrate the
communication with SQS. As such, it didn't appear to me that there is
anything to worry about my change, and the testing I did didn't discover
any issue. However, it turns out that while kombu's event loop doesn't
have actual multi-threading, its [reliance on
pycurl](https://github.com/celery/kombu/blob/main/kombu/asynchronous/http/curl.py#L48)
(and thus libcurl) meant that the requests to AWS were being done
asynchronously. On the other hand, boto3 requests are always done
synchronously, i.e. they are blocking requests.

The above meant that my change introduced blocking on the event loop of
kombu. This is fine in most of the cases, since the requests to SQS are
pretty fast. However, in the case of using long-polling, a call to SQS's
ReceiveMessage can last up to 20 seconds (depending on the user
configuration).

To solve this problem, I rolled back my earlier changes and, instead, to
address the issue reported in #1726, I now changed the
`AsyncSQSConnection` class such that it crafts either a `query` or a
`json` request depending on the protocol used by the SQS client. Thus,
when botocore changes the default protocol of SQS to JSON, kombu won't
be impacted, since it crafts its own request and, after my change, it
uses a hard-coded protocol based on the crafted requests.

This solution shouldn't be the final solution, and it is more of a
workaround that does the job for now. The final solution should be to
completely rely on boto3 for any communication with AWS, and ensuring
that all requests are async in nature (non-blocking.) This, however, is
a fundamental change that requires a lot of testing, in particular
performance testing.

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

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

* Update kombu/asynchronous/aws/sqs/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>
Co-authored-by: Asif Saif Uddin <auvipy@gmail.com>
2023-11-16 14:19:49 +06:00
jiangxianfu 3884eb9dd6
fix: redis requeue concurrency bug #1800 (#1805)
* fix: redis requeue concurrency bug  #1800

* fix: add unit test

* fix: update
2023-10-30 19:34:31 +06:00
Asif Saif Uddin 7187021ecc
using assert_called_once() in est__pop_ready_uses_lock (#1813) 2023-10-18 16:14:16 +06:00
Asif Saif Uddin 6c8e7e6b28
added Python 3.12 in the CI (#1812)
* added Python 3.12 in the CI

* try to make kafka work on py3.12

* skip kafka for the time being as it seems not woring with py3.12 yet

* using assert_called_once()
2023-10-18 15:50:39 +06:00
Peter Marheine 3ad075a536
Create a lock on cached_property if not present (#1811)
* Create a lock on cached_property if not present

This fixes #1804 (fixing breakage caused by use of undocumented
implementation details of functools.cached_property) by ensuring a lock
is always present on cached_property attributes, which is required to
safely support setting and deleting cached values in addition to
computing them on demand.

* Add a unit test for cached_property locking
2023-10-18 15:45:10 +06:00
Asif Saif Uddin 1dfe4f3c86
Revert "[fix #1726] Use boto3 for SQS async requests (#1759)" (#1799)
This reverts commit 862d0bc728.
2023-10-10 11:55:38 +06:00
Sergey Romanyuk 2454aa7a4d
Added as_uri method to MongoDB transport - Fixes #1795 (#1796)
* Added as_uri method to MongoDB transport, Added tests

* Make flake8 happy

* Removed unnecessary test
2023-10-04 23:00:35 +06:00
marnikow 0e445d108e
fix azure servicebus using managed identity support (#1801)
* azure servicebus: use DefaultAzureCredential in documentation

* azure servicebus: only use connection string when using sas key

* azure servicebus: add two small tests for paring of connection string

* azure servicebus: fix lint issues
2023-10-04 16:47:36 +06:00
flolas c18e9626e1 raise access denied error when ack 2023-09-04 02:16:00 +06:00
mbierma 492776eb7f
fix: Prevent redis task loss when closing connection while in poll (#1733)
* Catch brpop before closing connection

* Update unit test

---------

Co-authored-by: mbierma <3448579-mbierma@users.noreply.gitlab.com>
2023-08-15 10:16:49 +06:00
Rafid K 862d0bc728
[fix #1726] Use boto3 for SQS async requests (#1759)
* [fix #1726] Use boto3 for SQS async requests

* [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>
2023-06-27 10:06:41 +06:00
Tomer Nosrati 18edd4c848 Reverted unwanted constraint introduced in #1629 with max_retries not being able to be None (when it should) 2023-06-19 09:54:28 +06:00
Sebastian Kreft dd341709bf fix: allow deserializing any version of UUID
In PR #1575 a new serializer for UUIDs was introduced, however it fails when deserializing UUIDs which version is not within 1 and 5. Given that there's a new standard (https://datatracker.ietf.org/doc/html/draft-peabody-dispatch-new-uuid-format-04) ganining traction that introduces UUIDs v6, v7 and v8, we change the code to allow such versions.

In the test, we generate one UUID for each version using the package `uuid6` (https://github.com/oittaa/uuid6-python)
2023-06-15 18:57:24 +06:00
Daniel Garcia Moreno cb54c33f19 Support redis >= 4.5.2
The redis-py 4.5.2 changes the UnixDomainSocketConnection class so now
it inherits from AbstractConnection:
https://github.com/redis/redis-py/releases/tag/v4.5.2

This patch makes sure that the health_check_interval parameter is
checked for the __init__ method of the main class and also the bases, so
it doesn't fail with the newer version of redis-py.
2023-05-29 19:56:28 +06:00
Tom Sparrow 5062d53f94
SQS: avoid excessive GetQueueURL calls by using cached queue url (#1621)
* Fix #1618: avoid re-fetching queue URL when we already have it

`_get_from_sqs` was unnecessarily calling `get_queue_url` every
time even though the only place which calls `_get_from_sqs`
(that is `_get_async`) actually already knows the queue URL.

This change avoids hundreds of `GetQueueUrl` AWS API calls per hour
when using this SQS backend with celery.

Also `connection` is set by the one-and-only caller (and `queue` is
actually the queue name string now anyway so couldn't ever have
`.connection`) so remove the None default and unused fallback code.

* Clarify that `_new_queue` returns the queue URL

It seems that prior to 129a9e4ed0 it returned a queue
object but this is no longer the case so update comments
variable names accordingly to make it clearer.

Also remove the incorrect fallback which cannot
be correct any more given the return value has to
be the queue URL which must be a string.

* Unit test coverage for SQS async codepath

This key code path (which as far as I can see is
the main route when using celery with SQS) was
missing test coverage.

This test adds coverage for:
`_get_bulk_async` -> `_get_async` -> `_get_from_sqs`
2023-04-19 10:01:07 +06:00
Francis Charette-Migneault f86f1fc6e1
fix mongodb transport obsolete calls (#1694)
* fix mongodb transport obsolete calls + add test mock specs to check valid methods

* fix linting
2023-04-18 10:54:17 +06:00
Ismael Jiménez Sánchez ff031f73f2
fix: handle keyerror in azureservicebus transport when message is not found in qos and perform basic_ack (#1691)
* fix: handle keyerror when message is not found in qos and perform basic_ack

* fix: added tests for basic_ack

* fix: limit line length
2023-04-11 22:33:26 +06:00
Maxwell Muoto 9659f11ae1
Deprecate pytz and use zoneinfo (#1680)
* Main

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

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

* Fix

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

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

* Fix

* Trigger Build

* Fix

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

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

* Fix

* Fix

* noqas

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

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

* Fix

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

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

* remove unused noqa

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

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

* re-add import

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

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

* Fix

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

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

* Fixes

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

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

* use pytest-freezer (#1683)

* Main

* Trigger Build

* Fixes

* remove

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

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

* lint

* Lint

---------

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>
2023-04-09 14:08:23 +06:00