20318: Fix DiskCacheSize not propagated by (*KeepClient)Clone().
[arvados.git] / lib / dispatchcloud / cmd.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package dispatchcloud
6
7 import (
8         "context"
9         "fmt"
10
11         "git.arvados.org/arvados.git/lib/cmd"
12         "git.arvados.org/arvados.git/lib/service"
13         "git.arvados.org/arvados.git/sdk/go/arvados"
14         "github.com/prometheus/client_golang/prometheus"
15 )
16
17 var Command cmd.Handler = service.Command(arvados.ServiceNameDispatchCloud, newHandler)
18
19 func newHandler(ctx context.Context, cluster *arvados.Cluster, token string, reg *prometheus.Registry) service.Handler {
20         ac, err := arvados.NewClientFromConfig(cluster)
21         if err != nil {
22                 return service.ErrorHandler(ctx, cluster, fmt.Errorf("error initializing client from cluster config: %s", err))
23         }
24         // Disable auto-retry.  We have transient failure recovery at
25         // the application level, so we would rather receive/report
26         // upstream errors right away.
27         ac.Timeout = 0
28         d := &dispatcher{
29                 Cluster:   cluster,
30                 Context:   ctx,
31                 ArvClient: ac,
32                 AuthToken: token,
33                 Registry:  reg,
34         }
35         go d.Start()
36         return d
37 }