You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

check_upgradable_plugin_task.py 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import time
  2. import click
  3. import app
  4. from extensions.ext_database import db
  5. from models.account import TenantPluginAutoUpgradeStrategy
  6. from tasks.process_tenant_plugin_autoupgrade_check_task import process_tenant_plugin_autoupgrade_check_task
  7. AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL = 15 * 60 # 15 minutes
  8. @app.celery.task(queue="plugin")
  9. def check_upgradable_plugin_task():
  10. click.echo(click.style("Start check upgradable plugin.", fg="green"))
  11. start_at = time.perf_counter()
  12. now_seconds_of_day = time.time() % 86400 - 30 # we assume the tz is UTC
  13. click.echo(click.style("Now seconds of day: {}".format(now_seconds_of_day), fg="green"))
  14. strategies = (
  15. db.session.query(TenantPluginAutoUpgradeStrategy)
  16. .filter(
  17. TenantPluginAutoUpgradeStrategy.upgrade_time_of_day >= now_seconds_of_day,
  18. TenantPluginAutoUpgradeStrategy.upgrade_time_of_day
  19. < now_seconds_of_day + AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL,
  20. TenantPluginAutoUpgradeStrategy.strategy_setting
  21. != TenantPluginAutoUpgradeStrategy.StrategySetting.DISABLED,
  22. )
  23. .all()
  24. )
  25. for strategy in strategies:
  26. process_tenant_plugin_autoupgrade_check_task.delay(
  27. strategy.tenant_id,
  28. strategy.strategy_setting,
  29. strategy.upgrade_time_of_day,
  30. strategy.upgrade_mode,
  31. strategy.exclude_plugins,
  32. strategy.include_plugins,
  33. )
  34. end_at = time.perf_counter()
  35. click.echo(
  36. click.style(
  37. "Checked upgradable plugin success latency: {}".format(end_at - start_at),
  38. fg="green",
  39. )
  40. )