MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / Publish

Method Publish

module/strategy/iml.go:315–350  ·  view source on GitHub ↗
(ctx context.Context, driver string, scope string, target string)

Source from the content-addressed store, hash-verified

313}
314
315func (i *imlStrategyModule) Publish(ctx context.Context, driver string, scope string, target string) error {
316 d, has := strategy_driver.GetDriver(driver)
317 if !has {
318 return fmt.Errorf("driver not found: %s", driver)
319 }
320 list, err := i.strategyService.AllByDriver(ctx, driver, strategy_dto.ToScope(scope).Int(), target)
321 if err != nil {
322 return err
323 }
324
325 return i.transaction.Transaction(ctx, func(txCtx context.Context) error {
326 publishStrategies := make([]*eosc.Base[gateway.StrategyRelease], 0, len(list))
327 for _, l := range list {
328 if l.IsDelete {
329 err = i.strategyService.Delete(ctx, l.Id)
330 if err != nil {
331 return err
332 }
333 }
334 publishStrategies = append(publishStrategies, d.ToRelease(strategy_dto.ToStrategy(l), nil, 5000))
335
336 err = i.strategyService.CommitStrategy(txCtx, scope, target, l.Id, l)
337 if err != nil {
338 return err
339 }
340 }
341 client, err := i.clusterService.GatewayClient(ctx, cluster.DefaultClusterID)
342 if err != nil {
343 return err
344 }
345 defer func() {
346 _ = client.Close(ctx)
347 }()
348 return client.Strategy().Online(ctx, publishStrategies...)
349 })
350}
351
352func (i *imlStrategyModule) Delete(ctx context.Context, id string) error {
353 _, err := i.strategyService.LatestStrategyCommit(ctx, strategy_dto.ScopeGlobal, "", id)

Callers

nothing calls this directly

Calls 10

GetDriverMethod · 0.80
AllByDriverMethod · 0.65
DeleteMethod · 0.65
ToReleaseMethod · 0.65
CommitStrategyMethod · 0.65
GatewayClientMethod · 0.65
CloseMethod · 0.65
OnlineMethod · 0.65
StrategyMethod · 0.65
IntMethod · 0.45

Tested by

no test coverage detected