-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix/remove ee from mit #4682
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
Merged
Merged
Fix/remove ee from mit #4682
Changes from 4 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
f47cc6e
Remove some ee imports
Weves 50b28e0
more
Weves 77d2149
Remove all ee imports
Weves 3a9dcf8
Fix
Weves ba06632
Autodiscover
Weves 966a754
fix
Weves 63b8e05
Fix typing
Weves d321d7f
More celery task stuff
Weves 999afce
Fix import
Weves File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import time | ||
|
||
from celery import shared_task | ||
from celery import Task | ||
from celery.exceptions import SoftTimeLimitExceeded | ||
from redis.lock import Lock as RedisLock | ||
|
||
from ee.onyx.server.tenants.product_gating import get_gated_tenants | ||
from onyx.background.celery.apps.app_base import task_logger | ||
from onyx.background.celery.tasks.beat_schedule import BEAT_EXPIRES_DEFAULT | ||
from onyx.configs.constants import CELERY_GENERIC_BEAT_LOCK_TIMEOUT | ||
from onyx.configs.constants import ONYX_CLOUD_TENANT_ID | ||
from onyx.configs.constants import OnyxCeleryPriority | ||
from onyx.configs.constants import OnyxCeleryTask | ||
from onyx.configs.constants import OnyxRedisLocks | ||
from onyx.db.engine import get_all_tenant_ids | ||
from onyx.redis.redis_pool import get_redis_client | ||
from onyx.redis.redis_pool import redis_lock_dump | ||
from shared_configs.configs import IGNORED_SYNCING_TENANT_LIST | ||
|
||
|
||
@shared_task( | ||
name=OnyxCeleryTask.CLOUD_BEAT_TASK_GENERATOR, | ||
ignore_result=True, | ||
trail=False, | ||
bind=True, | ||
) | ||
def cloud_beat_task_generator( | ||
self: Task, | ||
task_name: str, | ||
queue: str = OnyxCeleryTask.DEFAULT, | ||
priority: int = OnyxCeleryPriority.MEDIUM, | ||
expires: int = BEAT_EXPIRES_DEFAULT, | ||
) -> bool | None: | ||
"""a lightweight task used to kick off individual beat tasks per tenant.""" | ||
time_start = time.monotonic() | ||
|
||
redis_client = get_redis_client(tenant_id=ONYX_CLOUD_TENANT_ID) | ||
|
||
lock_beat: RedisLock = redis_client.lock( | ||
f"{OnyxRedisLocks.CLOUD_BEAT_TASK_GENERATOR_LOCK}:{task_name}", | ||
timeout=CELERY_GENERIC_BEAT_LOCK_TIMEOUT, | ||
) | ||
|
||
# these tasks should never overlap | ||
if not lock_beat.acquire(blocking=False): | ||
return None | ||
|
||
last_lock_time = time.monotonic() | ||
tenant_ids: list[str] = [] | ||
num_processed_tenants = 0 | ||
|
||
try: | ||
tenant_ids = get_all_tenant_ids() | ||
gated_tenants = get_gated_tenants() | ||
for tenant_id in tenant_ids: | ||
if tenant_id in gated_tenants: | ||
continue | ||
|
||
current_time = time.monotonic() | ||
if current_time - last_lock_time >= (CELERY_GENERIC_BEAT_LOCK_TIMEOUT / 4): | ||
lock_beat.reacquire() | ||
last_lock_time = current_time | ||
|
||
# needed in the cloud | ||
if IGNORED_SYNCING_TENANT_LIST and tenant_id in IGNORED_SYNCING_TENANT_LIST: | ||
continue | ||
|
||
self.app.send_task( | ||
task_name, | ||
kwargs=dict( | ||
tenant_id=tenant_id, | ||
), | ||
queue=queue, | ||
priority=priority, | ||
expires=expires, | ||
ignore_result=True, | ||
) | ||
|
||
num_processed_tenants += 1 | ||
except SoftTimeLimitExceeded: | ||
task_logger.info( | ||
"Soft time limit exceeded, task is being terminated gracefully." | ||
) | ||
except Exception: | ||
task_logger.exception("Unexpected exception during cloud_beat_task_generator") | ||
finally: | ||
if not lock_beat.owned(): | ||
task_logger.error( | ||
"cloud_beat_task_generator - Lock not owned on completion" | ||
) | ||
redis_lock_dump(lock_beat, redis_client) | ||
else: | ||
lock_beat.release() | ||
|
||
time_elapsed = time.monotonic() - time_start | ||
task_logger.info( | ||
f"cloud_beat_task_generator finished: " | ||
f"task={task_name} " | ||
f"num_processed_tenants={num_processed_tenants} " | ||
f"num_tenants={len(tenant_ids)} " | ||
f"elapsed={time_elapsed:.2f}" | ||
) | ||
return True |
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.