Skip to content

Commit

Permalink
feat: return order IDs after price prediction (#1682)
Browse files Browse the repository at this point in the history
  • Loading branch information
3Hren committed Nov 7, 2018
1 parent 006ce62 commit dfcb668
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 21 deletions.
2 changes: 0 additions & 2 deletions optimus/engine.go
Expand Up @@ -354,8 +354,6 @@ func (m *workerEngine) execute(ctx context.Context) error {
// Extract the order ID for whose the selling plan is created.
orderID := plan.GetOrderID()

// Then we need to clean this, because otherwise worker rejects such request.
plan.OrderID = nil
plan.Identity = m.cfg.Identity
plan.Tag = m.tagger.Tag()

Expand Down
3 changes: 2 additions & 1 deletion optimus/optimus.go
Expand Up @@ -91,7 +91,8 @@ func (m *Optimus) Run(ctx context.Context) error {
}

// TODO: Well, 10 parameters seems to be WAT.
control, err := newWorkerEngine(cfg, ethAddr, masterAddr, blacklist, worker, market.Market(), marketCache, benchmarkMapping, newTagger(m.version), m.log)
workerClient := &workerManagementClientAPI{worker}
control, err := newWorkerEngine(cfg, ethAddr, masterAddr, blacklist, workerClient, market.Market(), marketCache, benchmarkMapping, newTagger(m.version), m.log)
if err != nil {
return err
}
Expand Down
10 changes: 9 additions & 1 deletion optimus/predictor_service.go
Expand Up @@ -71,5 +71,13 @@ func (m *PredictorService) PredictSupplier(ctx context.Context, request *sonm.Pr
return nil, err
}

return &sonm.PredictSupplierReply{Price: sonm.SumPrice(worker.Result)}, nil
orderIDs := make([]*sonm.BigInt, 0, len(worker.Result))
for _, plan := range worker.Result {
orderIDs = append(orderIDs, plan.GetOrderID())
}

return &sonm.PredictSupplierReply{
Price: sonm.SumPrice(worker.Result),
OrderIDs: orderIDs,
}, nil
}
11 changes: 11 additions & 0 deletions optimus/worker.go
Expand Up @@ -68,6 +68,17 @@ type WorkerManagementClientAPI interface {
NextMaintenance(ctx context.Context, request *sonm.Empty, opts ...grpc.CallOption) (*sonm.Timestamp, error)
}

type workerManagementClientAPI struct {
WorkerManagementClientAPI
}

func (m *workerManagementClientAPI) CreateAskPlan(ctx context.Context, request *sonm.AskPlan, opts ...grpc.CallOption) (*sonm.ID, error) {
// We need to clean this, because otherwise worker rejects such request.
request.OrderID = nil

return m.WorkerManagementClientAPI.CreateAskPlan(ctx, request, opts...)
}

// WorkerManagementClientExt extends default "WorkerManagementClient" with an
// ability to remove multiple ask-plans.
type WorkerManagementClientExt interface {
Expand Down
44 changes: 27 additions & 17 deletions proto/optimus.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions proto/optimus.proto
@@ -1,5 +1,6 @@
syntax = "proto3";

import "bigint.proto";
import "insonmnia.proto";
import "marketplace.proto";
import "worker.proto";
Expand All @@ -17,4 +18,5 @@ message PredictSupplierRequest {

message PredictSupplierReply {
Price price = 1;
repeated BigInt orderIDs = 2;
}

0 comments on commit dfcb668

Please sign in to comment.