simplify call to peer
This commit is contained in:
		@@ -4,7 +4,6 @@ import (
 | 
			
		||||
	"encoding/json"
 | 
			
		||||
	"errors"
 | 
			
		||||
	"fmt"
 | 
			
		||||
	"strings"
 | 
			
		||||
	"time"
 | 
			
		||||
 | 
			
		||||
	"cloud.o-forge.io/core/oc-lib/models/peer"
 | 
			
		||||
@@ -38,16 +37,11 @@ type Workflow struct {
 | 
			
		||||
	AbstractWorkflow
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func (wfa *Workflow) CheckBooking(subPath string, caller *tools.HTTPCaller) (bool, error) {
 | 
			
		||||
func (wfa *Workflow) CheckBooking(caller *tools.HTTPCaller) (bool, error) {
 | 
			
		||||
	// check if
 | 
			
		||||
	if wfa.Schedule == nil || wfa.Schedule.Start == nil || wfa.Graph == nil {
 | 
			
		||||
	if wfa.Graph == nil {
 | 
			
		||||
		return false, nil
 | 
			
		||||
	}
 | 
			
		||||
	if wfa.Schedule.End == nil {
 | 
			
		||||
		// if no end... then Book like a savage
 | 
			
		||||
		return true, nil
 | 
			
		||||
	}
 | 
			
		||||
	e := *wfa.Schedule.End
 | 
			
		||||
	accessor := (&datacenter.DatacenterResource{}).GetAccessor(nil)
 | 
			
		||||
	for _, link := range wfa.Graph.Links {
 | 
			
		||||
		if ok, dc_id := wfa.isDCLink(link); ok {
 | 
			
		||||
@@ -60,14 +54,7 @@ func (wfa *Workflow) CheckBooking(subPath string, caller *tools.HTTPCaller) (boo
 | 
			
		||||
			if peerID == "" {
 | 
			
		||||
				return false, errors.New("no peer id")
 | 
			
		||||
			}
 | 
			
		||||
			p, code, err := (&peer.Peer{}).GetAccessor(nil).LoadOne(peerID)
 | 
			
		||||
			if code != 200 {
 | 
			
		||||
				return false, err
 | 
			
		||||
			}
 | 
			
		||||
			subPath = strings.ReplaceAll(subPath, ":datacenter_id", fmt.Sprintf("%v", dc_id))
 | 
			
		||||
			subPath = strings.ReplaceAll(subPath, ":start_date", wfa.getFormat(wfa.Schedule.Start))
 | 
			
		||||
			subPath = strings.ReplaceAll(subPath, ":end_date", wfa.getFormat(&e))
 | 
			
		||||
			_, err = p.(*peer.Peer).LaunchPeerExecution(peerID, "", p.(*peer.Peer).Url+subPath, utils.BOOKING, tools.GET, nil, caller)
 | 
			
		||||
			_, err := (&peer.Peer{}).LaunchPeerExecution(peerID, dc_id, utils.BOOKING, tools.GET, nil, caller)
 | 
			
		||||
			if err != nil {
 | 
			
		||||
				return false, err
 | 
			
		||||
			}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user