Skip to content

Commit

Permalink
async fixes after rebase
Browse files Browse the repository at this point in the history
Signed-off-by: Andreas Jansson <[email protected]>
  • Loading branch information
andreasjansson committed Jan 4, 2021
1 parent fceb76b commit 4ec155b
Show file tree
Hide file tree
Showing 35 changed files with 2,816 additions and 3,675 deletions.
3 changes: 1 addition & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ ENVIRONMENT := development
OS := $(shell uname -s)

.PHONY: build
build:
cd proto && $(MAKE) build
build: verify-dev-env
cd go && $(MAKE) build-all ENVIRONMENT=$(ENVIRONMENT)
cd python && $(MAKE) build

Expand Down
5 changes: 2 additions & 3 deletions go/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ require (
github.com/go-bindata/go-bindata v3.1.2+incompatible
github.com/golang/protobuf v1.4.3
github.com/golangci/golangci-lint v1.32.2
github.com/google/martian v2.1.1-0.20190517191504-25dcb96d9e51+incompatible // indirect
github.com/hashicorp/go-uuid v1.0.2
github.com/kami-zh/go-capturer v0.0.0-20171211120116-e492ea43421d
github.com/logrusorgru/aurora v2.0.3+incompatible
Expand All @@ -33,8 +32,8 @@ require (
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 // indirect
golang.org/x/tools v0.0.0-20201121010211-780cb80bd7fb
google.golang.org/api v0.29.0
google.golang.org/genproto v0.0.0-20200527145253-8367513e4ece
google.golang.org/api v0.32.0
google.golang.org/genproto v0.0.0-20200921151605-7abf4a1a14d5
google.golang.org/grpc v1.33.2
google.golang.org/protobuf v1.25.0
gotest.tools/gotestsum v0.5.2
Expand Down
112 changes: 37 additions & 75 deletions go/go.sum

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions go/pkg/config/load.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func FindConfigInWorkingDir(overrideDir string) (conf *Config, projectDir string
if overrideDir != "" {
conf, err := LoadConfig(path.Join(overrideDir, global.ConfigFilenames[0]))
if err != nil {
if _, ok := err.(*configNotFoundError); ok {

if errors.IsConfigNotFound(err) {
// Try to locate replicate.yml
conf, err := LoadConfig(path.Join(overrideDir, global.ConfigFilenames[1]))
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions go/pkg/errors/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ func IsDoesNotExist(err error) bool {
return Code(err) == CodeDoesNotExist
}

func IsConfigNotFound(err error) bool {
return Code(err) == CodeConfigNotFound
}

func DoesNotExist(msg string) error { return &codedError{code: CodeDoesNotExist, msg: msg} }
func ReadError(msg string) error { return &codedError{code: CodeReadError, msg: msg} }
func WriteError(msg string) error { return &codedError{code: CodeWriteError, msg: msg} }
Expand Down
31 changes: 31 additions & 0 deletions go/pkg/param/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ const (
TypeBool Type = "bool"
TypeObject Type = "object"
TypeNone Type = "none"

// hack in nan, +inf and -inf since json doesn't support
// them natively.
JsonNaN = `"[NaN]"`
JsonPositiveInfinity = `"[+Infinity]"`
JsonNegativeInfinity = `"[-Infinity]"`
)

// TODO(bfirsh): could complexity be reduced here if it were implemented as interface{}?
Expand All @@ -39,6 +45,15 @@ func (v Value) MarshalJSON() ([]byte, error) {
case v.intVal != nil:
return json.Marshal(v.intVal)
case v.floatVal != nil:
if math.IsNaN(*v.floatVal) {
return []byte(JsonNaN), nil
}
if math.IsInf(*v.floatVal, 1) {
return []byte(JsonPositiveInfinity), nil
}
if math.IsInf(*v.floatVal, -1) {
return []byte(JsonNegativeInfinity), nil
}
return json.Marshal(v.floatVal)
case v.stringVal != nil:
return json.Marshal(v.stringVal)
Expand Down Expand Up @@ -71,6 +86,21 @@ func (v *Value) UnmarshalJSON(data []byte) error {
v.isNone = true
return nil
}
if string(data) == JsonNaN {
f := math.NaN()
v.floatVal = &f
return nil
}
if string(data) == JsonPositiveInfinity {
f := math.Inf(1)
v.floatVal = &f
return nil
}
if string(data) == JsonNegativeInfinity {
f := math.Inf(-1)
v.floatVal = &f
return nil
}
if s := new(string); json.Unmarshal(data, s) == nil {
v.stringVal = s
return nil
Expand All @@ -83,6 +113,7 @@ func (v *Value) UnmarshalJSON(data []byte) error {
func ParseFromString(s string) Value {
data := []byte(s)
v := Value{}

if s == "null" || s == "None" {
v.isNone = true
return v
Expand Down
4 changes: 4 additions & 0 deletions go/pkg/project/heartbeat.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ func CreateHeartbeat(repo repository.Repository, experimentID string, t time.Tim
return repo.Put(path.Join("metadata", "heartbeats", experimentID+".json"), data)
}

func DeleteHeartbeat(repo repository.Repository, experimentID string) error {
return repo.Delete(path.Join("metadata", "heartbeats", experimentID+".json"))
}

func listHeartbeats(repo repository.Repository) ([]*Heartbeat, error) {
paths, err := repo.List("metadata/heartbeats/")
if err != nil {
Expand Down
8 changes: 8 additions & 0 deletions go/pkg/project/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,14 @@ func (p *Project) RefreshHeartbeat(experimentID string) error {
return CreateHeartbeat(p.repository, experimentID, time.Now().UTC())
}

func (p *Project) StopExperiment(experimentID string) error {
if err := DeleteHeartbeat(p.repository, experimentID); err != nil {
return err
}
p.invalidateCache()
return nil
}

func (p *Project) invalidateCache() {
p.hasLoaded = false
}
Expand Down
2 changes: 2 additions & 0 deletions go/pkg/repository/s3_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build external

package repository

import (
Expand Down
Loading

0 comments on commit 4ec155b

Please sign in to comment.