MCPcopy
hub / github.com/mudler/LocalAI / backendHandler

Method backendHandler

core/services/galleryop/backends.go:21–142  ·  view source on GitHub ↗
(op *ManagementOp[gallery.GalleryBackend, any], systemState *system.SystemState)

Source from the content-addressed store, hash-verified

19)
20
21func (g *GalleryService) backendHandler(op *ManagementOp[gallery.GalleryBackend, any], systemState *system.SystemState) error {
22 utils.ResetDownloadTimers()
23
24 // Dedup check in distributed mode — skip if another instance is already processing this element
25 if g.galleryStore != nil && op.GalleryElementName != "" {
26 dup, err := g.galleryStore.FindDuplicate(op.GalleryElementName)
27 if err == nil && dup != nil && dup.ID != op.ID {
28 g.UpdateStatus(op.ID, &OpStatus{
29 Processed: true,
30 Message: fmt.Sprintf("already being processed by another instance (op %s)", dup.ID),
31 })
32 return nil
33 }
34 }
35
36 // Check if already cancelled
37 if op.Context != nil {
38 select {
39 case <-op.Context.Done():
40 g.UpdateStatus(op.ID, &OpStatus{
41 Cancelled: true,
42 Processed: true,
43 Message: "cancelled",
44 GalleryElementName: op.GalleryElementName,
45 })
46 return op.Context.Err()
47 default:
48 }
49 }
50
51 g.UpdateStatus(op.ID, &OpStatus{Message: fmt.Sprintf("processing backend: %s", op.GalleryElementName), Progress: 0, Cancellable: true})
52
53 // displayDownload displays the download progress
54 progressCallback := func(fileName string, current string, total string, percentage float64) {
55 // Check for cancellation during progress updates
56 if op.Context != nil {
57 select {
58 case <-op.Context.Done():
59 return
60 default:
61 }
62 }
63 g.UpdateStatus(op.ID, &OpStatus{Message: fmt.Sprintf(processingMessage, fileName, total, current), FileName: fileName, Progress: percentage, TotalFileSize: total, DownloadedFileSize: current, Cancellable: true})
64 utils.DisplayDownloadFunction(fileName, current, total, percentage)
65 }
66
67 ctx := op.Context
68 if ctx == nil {
69 ctx = context.Background()
70 }
71
72 var err error
73 if op.Upgrade {
74 err = g.backendManager.UpgradeBackend(ctx, op.ID, op.GalleryElementName, progressCallback)
75 } else if op.Delete {
76 err = g.backendManager.DeleteBackend(op.GalleryElementName)
77 } else {
78 err = g.backendManager.InstallBackend(ctx, op, progressCallback)

Callers 1

StartMethod · 0.95

Calls 12

UpdateStatusMethod · 0.95
ResetDownloadTimersFunction · 0.92
DisplayDownloadFunctionFunction · 0.92
DeleteBackendFromSystemFunction · 0.92
FindDuplicateMethod · 0.80
ErrMethod · 0.80
UpgradeBackendMethod · 0.65
DeleteBackendMethod · 0.65
InstallBackendMethod · 0.65
IsMethod · 0.45
ErrorMethod · 0.45

Tested by

no test coverage detected