...
1
18
19 package scheduler_service
20
21 import (
22 "scheduler/api/api_monitoring"
23 "scheduler/log"
24 "scheduler/types"
25 "strconv"
26 )
27
28
29 func GetLoad(host string) (int, *APIResponse, error) {
30 res, err := monitoringLoadGetApiCall(host)
31 if err != nil {
32 log.Log.Debugf("Cannot get load from scheduler service: %s", err.Error())
33 return -1, res, err
34 }
35
36 currentRunningFunctions, err := strconv.Atoi(res.Headers.Get(api_monitoring.ApiMonitoringLoadHeaderKey))
37 if err != nil {
38 log.Log.Debugf("Cannot get load from scheduler service: %s", err.Error())
39 return -1, res, err
40 }
41
42 queueLen, err := strconv.Atoi(res.Headers.Get(api_monitoring.ApiMonitoringQueueLengthHeaderKey))
43 if err != nil {
44 log.Log.Debugf("Cannot get load from scheduler service: %s", err.Error())
45 return -1, res, err
46 }
47
48 return currentRunningFunctions + queueLen, nil, nil
49 }
50
51
52 func ExecuteFunction(host string, peerRequest *types.PeerJobRequest) (*APIResponse, error) {
53 res, err := peerFunctionApiCall(host, peerRequest)
54 if err != nil {
55 log.Log.Errorf("[R#%d,T%s] Cannot execute function on peer: %s", peerRequest.ServiceIdRequest, peerRequest.ServiceIdTracing, err.Error())
56 return res, err
57 }
58
59 return res, nil
60 }
61
View as plain text