fix: bugs

pull/19758/head
Junyan Qin 11 months ago
parent ea7acb3d2b
commit 6f84aac027
No known key found for this signature in database
GPG Key ID: 22FE3AFADC710CEB

@ -110,7 +110,7 @@ def init_app(app: DifyApp) -> Celery:
# every 15 minutes # every 15 minutes
"check_upgradable_plugin_task": { "check_upgradable_plugin_task": {
"task": "schedule.check_upgradable_plugin_task.check_upgradable_plugin_task", "task": "schedule.check_upgradable_plugin_task.check_upgradable_plugin_task",
"schedule": timedelta(minutes=15), "schedule": crontab(minute="*/15"),
}, },
} }
celery_app.conf.update(beat_schedule=beat_schedule, imports=imports) celery_app.conf.update(beat_schedule=beat_schedule, imports=imports)

@ -1,4 +1,5 @@
import time import time
import traceback
import click import click
@ -14,12 +15,13 @@ AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL = 15 * 60 # 15 minutes
RETRY_TIMES_OF_ONE_PLUGIN_IN_ONE_TENANT = 3 RETRY_TIMES_OF_ONE_PLUGIN_IN_ONE_TENANT = 3
@app.celery.task(queue="dataset") @app.celery.task(queue="plugin")
def check_upgradable_plugin_task(): def check_upgradable_plugin_task():
click.echo(click.style("Start check upgradable plugin.", fg="green")) click.echo(click.style("Start check upgradable plugin.", fg="green"))
start_at = time.perf_counter() start_at = time.perf_counter()
now_seconds_of_day = time.time() % 86400 # we assume the tz is UTC now_seconds_of_day = time.time() % 86400 # we assume the tz is UTC
click.echo(click.style("Now seconds of day: {}".format(now_seconds_of_day), fg="green"))
# get strategies that set to be performed in the next AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL # get strategies that set to be performed in the next AUTO_UPGRADE_MINIMAL_CHECKING_INTERVAL
strategies = ( strategies = (
@ -69,50 +71,70 @@ def check_upgradable_plugin_task():
if not plugin_ids: if not plugin_ids:
continue continue
plugin_ids_plain_list = [plugin_id for plugin_id, _, _ in plugin_ids]
click.echo(click.style("Fetching manifests for plugins: {}".format(plugin_ids_plain_list), fg="green"))
# fetch latest versions from marketplace # fetch latest versions from marketplace
manifests = marketplace.batch_fetch_plugin_manifests(plugin_ids) manifests = marketplace.batch_fetch_plugin_manifests(plugin_ids_plain_list)
for manifest in manifests: for manifest in manifests:
for plugin_id, version, original_unique_identifier in plugin_ids: for plugin_id, version, original_unique_identifier in plugin_ids:
current_version = version if manifest.plugin_id != plugin_id:
latest_version = manifest.latest_version continue
# @yeuoly review here try:
def fix_only_checker(latest_version, current_version): current_version = version
latest_version_tuple = tuple(int(val) for val in latest_version.split(".")) latest_version = manifest.latest_version
current_version_tuple = tuple(int(val) for val in current_version.split("."))
# @yeuoly review here
if ( def fix_only_checker(latest_version, current_version):
latest_version_tuple[0] == current_version_tuple[0] latest_version_tuple = tuple(int(val) for val in latest_version.split("."))
and latest_version_tuple[1] == current_version_tuple[1] current_version_tuple = tuple(int(val) for val in current_version.split("."))
):
return latest_version_tuple[2] != current_version_tuple[2] if (
return False latest_version_tuple[0] == current_version_tuple[0]
and latest_version_tuple[1] == current_version_tuple[1]
version_checker = { ):
TenantPluginAutoUpgradeStrategy.StrategySetting.LATEST: lambda latest_version, return latest_version_tuple[2] != current_version_tuple[2]
current_version: latest_version != current_version, return False
TenantPluginAutoUpgradeStrategy.StrategySetting.FIX_ONLY: fix_only_checker,
} version_checker = {
TenantPluginAutoUpgradeStrategy.StrategySetting.LATEST: lambda latest_version,
if version_checker[strategy_setting](latest_version, current_version): current_version: latest_version != current_version,
# execute upgrade TenantPluginAutoUpgradeStrategy.StrategySetting.FIX_ONLY: fix_only_checker,
new_unique_identifier = manifest.latest_package_identifier }
marketplace.record_install_plugin_event(new_unique_identifier) if version_checker[strategy_setting](latest_version, current_version):
click.echo(click.style("Upgrade plugin: {}".format(new_unique_identifier), fg="green")) # execute upgrade
task_start_resp = manager.upgrade_plugin( new_unique_identifier = manifest.latest_package_identifier
tenant_id,
original_unique_identifier, marketplace.record_install_plugin_event(new_unique_identifier)
new_unique_identifier, click.echo(
PluginInstallationSource.Marketplace, click.style(
{ "Upgrade plugin: {} -> {}".format(
"plugin_unique_identifier": new_unique_identifier, original_unique_identifier, new_unique_identifier
}, ),
) fg="green",
)
)
task_start_resp = manager.upgrade_plugin(
tenant_id,
original_unique_identifier,
new_unique_identifier,
PluginInstallationSource.Marketplace,
{
"plugin_unique_identifier": new_unique_identifier,
},
)
except Exception as e:
click.echo(click.style("Error when upgrading plugin: {}".format(e), fg="red"))
traceback.print_exc()
break
except Exception as e: except Exception as e:
click.echo(click.style("Error when checking upgradable plugin: {}".format(e), fg="red")) click.echo(click.style("Error when checking upgradable plugin: {}".format(e), fg="red"))
traceback.print_exc()
continue continue
end_at = time.perf_counter() end_at = time.perf_counter()

Loading…
Cancel
Save