SyncTaskPluginsOnceContext loads the enabled plugin rows into the registry and records the ones this node runs differently from the database as the plugins sync topic's errors. A database error keeps the current plugins.
(ctx context.Context)
| 1049 | // and records the ones this node runs differently from the database as the |
| 1050 | // plugins sync topic's errors. A database error keeps the current plugins. |
| 1051 | func SyncTaskPluginsOnceContext(ctx context.Context) error { |
| 1052 | started := time.Now() |
| 1053 | taskPluginSyncState.Lock() |
| 1054 | defer taskPluginSyncState.Unlock() |
| 1055 | databaseSnapshot, err := model.GetTaskPluginSyncSnapshot() |
| 1056 | if err != nil { |
| 1057 | syncErr := fmt.Errorf("sync task plugins: %w", err) |
| 1058 | taskPluginSyncState.lastRebuild = taskPluginRebuildOutcome{ |
| 1059 | Status: "failed", |
| 1060 | AttemptedAt: time.Now(), |
| 1061 | Generation: jsplugin.DefaultRegistry.Generation().Number, |
| 1062 | DatabaseRevision: taskPluginSyncState.lastRebuild.DatabaseRevision, |
| 1063 | Error: syncErr.Error(), |
| 1064 | } |
| 1065 | logger.LogDebug( |
| 1066 | ctx, |
| 1067 | "task_plugin subsystem=sync event=failed stage=database_snapshot retained_generation=%d elapsed_ms=%d", |
| 1068 | jsplugin.DefaultRegistry.Generation().Number, |
| 1069 | time.Since(started).Milliseconds(), |
| 1070 | ) |
| 1071 | return syncErr |
| 1072 | } |
| 1073 | databasePlugins := databaseSnapshot.Plugins |
| 1074 | sort.Slice(databasePlugins, func(i, j int) bool { return databasePlugins[i].Key < databasePlugins[j].Key }) |
| 1075 | currentOverrides := jsplugin.DefaultRegistry.OverridePlugins() |
| 1076 | generationBefore := jsplugin.DefaultRegistry.Generation().Number |
| 1077 | logger.LogDebug( |
| 1078 | ctx, |
| 1079 | "task_plugin subsystem=sync event=start database_revision=%q generation=%d desired_plugins=%d current_overrides=%d", |
| 1080 | databaseSnapshot.Revision, |
| 1081 | generationBefore, |
| 1082 | len(databasePlugins), |
| 1083 | len(currentOverrides), |
| 1084 | ) |
| 1085 | nextOverrides := make([]*jsplugin.LoadedPlugin, 0, len(databasePlugins)) |
| 1086 | nextHashes := make(map[string]string, len(databasePlugins)) |
| 1087 | seen := make(map[string]bool, len(databasePlugins)) |
| 1088 | for _, plugin := range databasePlugins { |
| 1089 | seen[plugin.Key] = true |
| 1090 | if current := currentOverrides[plugin.Key]; current != nil && taskPluginSyncState.hashes[plugin.Key] == plugin.SourceHash { |
| 1091 | nextOverrides = append(nextOverrides, current) |
| 1092 | nextHashes[plugin.Key] = plugin.SourceHash |
| 1093 | logger.LogDebug( |
| 1094 | ctx, |
| 1095 | "task_plugin subsystem=sync event=plugin plugin=%q version=%q action=reuse", |
| 1096 | plugin.Key, |
| 1097 | plugin.Version, |
| 1098 | ) |
| 1099 | continue |
| 1100 | } |
| 1101 | logger.LogDebug( |
| 1102 | ctx, |
| 1103 | "task_plugin subsystem=sync event=plugin plugin=%q version=%q action=compile_start", |
| 1104 | plugin.Key, |
| 1105 | plugin.Version, |
| 1106 | ) |
| 1107 | var compiled *jsplugin.LoadedPlugin |
| 1108 | source, compileErr := model.GetTaskPluginSource(plugin.Id) |
no test coverage detected