fix: bugs

build/plugin-auto-upgrade
Junyan Qin 1 year ago
parent 8b62e5520a
commit c2520f7cb4
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,11 +71,19 @@ 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:
if manifest.plugin_id != plugin_id:
continue
try:
current_version = version current_version = version
latest_version = manifest.latest_version latest_version = manifest.latest_version
@ -100,7 +110,14 @@ def check_upgradable_plugin_task():
new_unique_identifier = manifest.latest_package_identifier new_unique_identifier = manifest.latest_package_identifier
marketplace.record_install_plugin_event(new_unique_identifier) marketplace.record_install_plugin_event(new_unique_identifier)
click.echo(click.style("Upgrade plugin: {}".format(new_unique_identifier), fg="green")) click.echo(
click.style(
"Upgrade plugin: {} -> {}".format(
original_unique_identifier, new_unique_identifier
),
fg="green",
)
)
task_start_resp = manager.upgrade_plugin( task_start_resp = manager.upgrade_plugin(
tenant_id, tenant_id,
original_unique_identifier, original_unique_identifier,
@ -110,9 +127,14 @@ def check_upgradable_plugin_task():
"plugin_unique_identifier": new_unique_identifier, "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