Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set tenant_cache_seconds globally #38

Merged
merged 17 commits into from
May 27, 2020
Merged

Conversation

awaazde
Copy link
Contributor

@awaazde awaazde commented May 4, 2020

Set tenant_cache_seconds globally

@awaazde awaazde changed the title master Set tenant_cache_seconds globally May 4, 2020
@maciej-gol
Copy link
Owner

maciej-gol commented May 4, 2020 via email

@awaazde
Copy link
Contributor Author

awaazde commented May 5, 2020

@maciej-gol I updated the code to what should be correct.

I'm stuck on test cases bc I can't get the test env to run. Can you see these errors and suggest how to get tests to work?

https://gist.github.com/awaazde/25af5604301f3112441983395d7c1f62
https://gist.github.com/awaazde/a5cfd3d94fd4383739fa82e17a1e61e5

@maciej-gol
Copy link
Owner

Just run the ./run-tests script. Requires docker-compose. It will print out some error tracebacks because of missing model objects, but these are expected errors. As long as pytest claims 100% success, then it's fine.

README.md Outdated Show resolved Hide resolved
@awaazde
Copy link
Contributor Author

awaazde commented May 6, 2020

Just run the ./run-tests script. Requires docker-compose. It will print out some error tracebacks because of missing model objects, but these are expected errors. As long as pytest claims 100% success, then it's fine.

Can you confirm this is output is expected? I don't think tests passed but not clear.

@awaazde
Copy link
Contributor Author

awaazde commented May 6, 2020

@maciej-gol looking at the implementation of SimpleCache, the storage here could get pretty big in memory over time depending on expiry length and how long the worker is alive.

Do you think it's a concern? Maybe the storage should clear expired entries?

@maciej-gol
Copy link
Owner

Can you confirm this is output is expected? I don't think tests passed but not clear.

Yes, it died. You can see it both in error messages before pytest was ran, and during pytest itself - some tests are reported as errors E. Can you rebase on top of newest master and rerun the script? It should declutter the output significantly so that we can debug it easier.

@maciej-gol looking at the implementation of SimpleCache, the storage here could get pretty big in memory over time depending on expiry length and how long the worker is alive.

Do you think it's a concern? Maybe the storage should clear expired entries?

I think it's a general good practice to setup celery so that it kills it's workers after a number of requests handled. CPython is known of being not so eager to let OS reclaim free memory.

Other than that, will look into existing LRU solutions so that I don't need to reimplement it.

@maciej-gol
Copy link
Owner

@awaazde there is an interesting package https://github.com/tkem/cachetools that I could use as TTLCache, I will need to sunset per-task cache setting in favor of the global one before proceeding.

@awaazde
Copy link
Contributor Author

awaazde commented May 7, 2020

Can you confirm this is output is expected? I don't think tests passed but not clear.

Yes, it died. You can see it both in error messages before pytest was ran, and during pytest itself - some tests are reported as errors E. Can you rebase on top of newest master and rerun the script? It should declutter the output significantly so that we can debug it easier.

Reran and result here. This looks much better can you confirm this is baseline passing? I will now add a test case

@maciej-gol
Copy link
Owner

...
app_1       | =========================== 8 passed in 3.20 seconds ===========================
tenant-schemas-celery_app_1 exited with code 0

Worked like a charm!

@awaazde
Copy link
Contributor Author

awaazde commented May 18, 2020

@maciej-gol this should be good to go. Added test coverage for the global var.

I spent several hours trying to track down why the setting was not being loaded by Celery config. I had to force load the settings in the test case, which ideally shouldn't be required. However I believe the fix is setting namespace="CELERY" here in test_app.py, but that seems to be failing because this somehow breaks the rabbitmq broker login.

I couldn't quite figure it out but if you can we may be able to remove this line

tenant_schemas_celery/task_test.py Outdated Show resolved Hide resolved
tenant_schemas_celery/test_app.py Outdated Show resolved Hide resolved
test_app/test_app/settings.py Outdated Show resolved Hide resolved
@maciej-gol
Copy link
Owner

If you would like me to help with the MR, I need access to your fork.

@awaazde
Copy link
Contributor Author

awaazde commented May 21, 2020

If you would like me to help with the MR, I need access to your fork.

Gave you access let me know if you're not able to.

@awaazde
Copy link
Contributor Author

awaazde commented May 21, 2020

@maciej-gol I've addressed all the comments above. My main concern is the versioning of this package seems off. You have labeled the pip package version 0.3.0, but master branch has python_requires>=3.6. According to the docs though, 0.x version is supposed to support Python 2.x.

So I believe that we need to either:

  • revert the line above in setup.py on master (I've done it on this fork currently)
  • create a branch off of tag 0.3.0, merge/backport these changes there, and either label that branch as v0.3.1 and/or tag it as v0.3.1. I've setup a separate PR Set tenant_cache_seconds globally (v.0.3.0) #42 for this, but this option doesn't seem ideal.

Let me know your thoughts.

awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
@maciej-gol
Copy link
Owner

maciej-gol commented May 21, 2020 via email

awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
awaazde pushed a commit to awaazde/tenant-schemas-celery that referenced this pull request May 21, 2020
@awaazde awaazde closed this May 21, 2020
@awaazde awaazde reopened this May 21, 2020
@awaazde
Copy link
Contributor Author

awaazde commented May 21, 2020

I will create the 0.x branch and back port the changes, no worries. czw., 21 maj 2020, 08:43 użytkownik Awaaz.De [email protected] napisał:

OK also closed PR #42 as it's not relevant

@awaazde
Copy link
Contributor Author

awaazde commented May 27, 2020

@maciej-gol, do you have an estimate on when you'll be able to merge and backport this enhancement for Python < 3.x?

We want to include the updated package in our next release, based on your timeline we can plan our release accordingly.

Thank you!

@maciej-gol
Copy link
Owner

I will merge it, then, and correct the tests later

@maciej-gol maciej-gol merged commit b09dd15 into maciej-gol:master May 27, 2020
maciej-gol added a commit that referenced this pull request May 27, 2020
* Issue #28: allow tenant_cache_seconds to be set globally

* Issue #28: allow tenant_cache_seconds to be set globally

* Issue #28: allow tenant_cache_seconds to be set globally

* Issue #28: allow tenant_cache_seconds to be set globally

* Revert "Issue #28: allow tenant_cache_seconds to be set globally"

This reverts commit 5c450f8

* Issue #28: allow tenant_cache_seconds to be set globally

* Issue #28: allow tenant_cache_seconds to be set globally

* don't assume user's namespace is CELERY

Co-authored-by: Maciej Gol <[email protected]>

* Issue #28: allow tenant_cache_seconds to be set globally, test case passing

* Issue #28: python 3.x version requirement shouldn't hold for 0.x (https://github.com/maciej-gol/tenant-schemas-celery#python-compatibility)

* Revert "Issue #28: python 3.x version requirement shouldn't hold for 0.x (https://github.com/maciej-gol/tenant-schemas-celery#python-compatibility)": this is appropriate for master.

This reverts commit e6db6a8

* Issue #28/PR #38: resolves #38 (comment)

* Issue #28/PR #38: resolves #38 (comment)

* Issue #28/PR #38: resolves #38 (review)

* Issue #28: Revert the last revert. Actually for version on master to be consistent with the docs (https://github.com/maciej-gol/tenant-schemas-celery#python-compatibility), we need to remove this

This reverts commit 134e92d

Co-authored-by: Neil Patel <[email protected]>
Co-authored-by: Maciej Gol <[email protected]>
@maciej-gol
Copy link
Owner

Released as 0.4.0.

@awaazde
Copy link
Contributor Author

awaazde commented May 28, 2020

@maciej-gol master branch is currently tagged with v0.3.0. Should that be bumped or changed to avoid confusion?

Also may need to tweak the docs slightly to mention the global setting introduced in 0.4.0

@maciej-gol
Copy link
Owner

maciej-gol commented May 28, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants