...
1
18
19 package queue
20
21 import (
22 "scheduler/config"
23 "scheduler/faas"
24 "scheduler/faas_openfaas"
25 "scheduler/log"
26 "scheduler/memdb"
27 "time"
28 )
29
30
31 func executeNow(job *QueuedJob) {
32 log.Log.Debugf("%s starting execution, with payload %t and type %s", job.Request.ServiceName, job.Request.Payload != nil, job.Request.PayloadContentType)
33
34 _ = memdb.SetFunctionRunning(job.Request.ServiceName, job.Request.ServiceType)
35
36 startExecutionTime := time.Now()
37
38 res, err := faas.FunctionExecute(job.Request.ServiceName, job.Request.Payload, job.Request.PayloadContentType)
39
40 if err != nil {
41 log.Log.Errorf("Cannot execute service %s: %s", job.Request.ServiceName, err.Error())
42 job.ErrorExecution = true
43 } else {
44 log.Log.Debugf("%s function executed", job.Request.ServiceName)
45
46
47 job.Response = res
48 job.Timings.ExecutionTime = time.Since(startExecutionTime).Seconds()
49 if config.GetOpenFaasEnabled() {
50 job.Timings.FaasExecutionTime = faas_openfaas.GetDurationFromExecuteApiCallResponse(res)
51 }
52 }
53
54 _ = memdb.SetFunctionStopped(job.Request.ServiceName, job.Request.ServiceType)
55
56
57 job.Semaphore.Signal()
58
59
60 consumersSem.Signal()
61 }
62
View as plain text