(ctx context.Context)
| 607 | } |
| 608 | |
| 609 | func syncTaskPluginsOnceContext(ctx context.Context) error { |
| 610 | started := time.Now() |
| 611 | taskPluginSyncState.Lock() |
| 612 | defer taskPluginSyncState.Unlock() |
| 613 | databaseSnapshot, err := model.GetTaskPluginSyncSnapshot() |
| 614 | if err != nil { |
| 615 | syncErr := fmt.Errorf("sync task plugins: %w", err) |
| 616 | taskPluginSyncState.lastRebuild = taskPluginRebuildOutcome{ |
| 617 | Status: "failed", |
| 618 | AttemptedAt: time.Now(), |
| 619 | Generation: jsplugin.DefaultRegistry.Generation().Number, |
| 620 | DatabaseRevision: taskPluginSyncState.lastRebuild.DatabaseRevision, |
| 621 | Error: syncErr.Error(), |
| 622 | } |
| 623 | logger.LogDebug( |
| 624 | ctx, |
| 625 | "task_plugin subsystem=sync event=failed stage=database_snapshot retained_generation=%d elapsed_ms=%d", |
| 626 | jsplugin.DefaultRegistry.Generation().Number, |
| 627 | time.Since(started).Milliseconds(), |
| 628 | ) |
| 629 | return syncErr |
| 630 | } |
| 631 | databasePlugins := databaseSnapshot.Plugins |
| 632 | sort.Slice(databasePlugins, func(i, j int) bool { return databasePlugins[i].Key < databasePlugins[j].Key }) |
| 633 | currentOverrides := jsplugin.DefaultRegistry.OverridePlugins() |
| 634 | generationBefore := jsplugin.DefaultRegistry.Generation().Number |
| 635 | logger.LogDebug( |
| 636 | ctx, |
| 637 | "task_plugin subsystem=sync event=start database_revision=%q generation=%d desired_plugins=%d current_overrides=%d", |
| 638 | databaseSnapshot.Revision, |
| 639 | generationBefore, |
| 640 | len(databasePlugins), |
| 641 | len(currentOverrides), |
| 642 | ) |
| 643 | nextOverrides := make([]*jsplugin.LoadedPlugin, 0, len(databasePlugins)) |
| 644 | nextHashes := make(map[string]string, len(databasePlugins)) |
| 645 | seen := make(map[string]bool, len(databasePlugins)) |
| 646 | for _, plugin := range databasePlugins { |
| 647 | seen[plugin.Key] = true |
| 648 | if current := currentOverrides[plugin.Key]; current != nil && taskPluginSyncState.hashes[plugin.Key] == plugin.SourceHash { |
| 649 | nextOverrides = append(nextOverrides, current) |
| 650 | nextHashes[plugin.Key] = plugin.SourceHash |
| 651 | logger.LogDebug( |
| 652 | ctx, |
| 653 | "task_plugin subsystem=sync event=plugin plugin=%q version=%q action=reuse", |
| 654 | plugin.Key, |
| 655 | plugin.Version, |
| 656 | ) |
| 657 | continue |
| 658 | } |
| 659 | logger.LogDebug( |
| 660 | ctx, |
| 661 | "task_plugin subsystem=sync event=plugin plugin=%q version=%q action=compile_start", |
| 662 | plugin.Key, |
| 663 | plugin.Version, |
| 664 | ) |
| 665 | compiled, compileErr := jsplugin.CompilePlugin(plugin.Source, jsplugin.Options{Key: plugin.Key, Version: plugin.Version}) |
| 666 | if compileErr != nil { |
no test coverage detected