Skip to content

Commit 24d7f49

Browse files
knopers8teo
authored andcommitted
[OCTRL-685][core] Publish CCDB EOR GRP also if we fail to start a run
1 parent 0df4670 commit 24d7f49

File tree

1 file changed

+41
-11
lines changed

1 file changed

+41
-11
lines changed

core/integration/ccdb/plugin.go

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ import (
3636
"github.com/AliceO2Group/Control/core/workflow/callable"
3737
"github.com/sirupsen/logrus"
3838
"github.com/spf13/viper"
39+
"go/types"
3940
"net/url"
4041
"os/exec"
4142
"strconv"
@@ -77,11 +78,17 @@ func NewGRPObject(varStack map[string]string) *GeneralRunParameters {
7778
return nil
7879
}
7980

80-
runNumber, err := strconv.ParseUint(varStack["run_number"], 10, 32)
81+
runNumberStr, ok := varStack["run_number"]
82+
if !ok {
83+
log.WithField("partition", envId).
84+
Error("cannot acquire run number for GRP object")
85+
return nil
86+
}
87+
runNumber, err := strconv.ParseUint(runNumberStr, 10, 32)
8188
if err != nil {
8289
log.WithError(err).
8390
WithField("partition", envId).
84-
Error("cannot acquire run number for Run Start")
91+
Errorf("cannot convert run number '%s' to an integer", runNumberStr)
8592
return nil
8693
}
8794

@@ -191,7 +198,8 @@ func NewGRPObject(varStack map[string]string) *GeneralRunParameters {
191198
}
192199

193200
type Plugin struct {
194-
ccdbUrl string
201+
ccdbUrl string
202+
existingRuns map[uint32]types.Nil // using map, because it is more convenient to add, find, delete elements than slice
195203
}
196204

197205
func NewPlugin(endpoint string) integration.Plugin {
@@ -204,7 +212,8 @@ func NewPlugin(endpoint string) integration.Plugin {
204212
}
205213

206214
return &Plugin{
207-
ccdbUrl: endpoint,
215+
ccdbUrl: endpoint,
216+
existingRuns: make(map[uint32]types.Nil),
208217
}
209218
}
210219

@@ -314,7 +323,13 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
314323
stack["RunStart"] = func() (out string) { // must formally return string even when we return nothing
315324
log.WithField("call", "RunStart").
316325
WithField("partition", envId).Debug("performing CCDB interface Run Start")
317-
err := p.uploadCurrentGRP(varStack, envId, true)
326+
327+
grp := NewGRPObject(varStack)
328+
if grp == nil {
329+
return
330+
}
331+
p.existingRuns[grp.runNumber] = types.Nil{}
332+
err := p.uploadCurrentGRP(grp, envId, true)
318333
if err != nil {
319334
log.WithField("call", "RunStop").
320335
WithField("partition", envId).Error(err.Error())
@@ -323,19 +338,34 @@ func (p *Plugin) CallStack(data interface{}) (stack map[string]interface{}) {
323338
}
324339
stack["RunStop"] = func() (out string) {
325340
log.WithField("call", "RunStop").
326-
WithField("partition", envId).Debug("performing CCDB interface Run Stop")
327-
err := p.uploadCurrentGRP(varStack, envId, false)
328-
if err != nil {
341+
WithField("partition", envId).Debug("checking if a CCDB End Of Run GRP should be published")
342+
343+
grp := NewGRPObject(varStack)
344+
if grp == nil {
329345
log.WithField("call", "RunStop").
330-
WithField("partition", envId).Error(err.Error())
346+
WithField("partition", envId).
347+
Debug("probably went to ERROR while not in RUNNING, doing nothing")
348+
return
349+
}
350+
_, runExists := p.existingRuns[grp.runNumber]
351+
if runExists {
352+
delete(p.existingRuns, grp.runNumber)
353+
err := p.uploadCurrentGRP(grp, envId, false)
354+
if err != nil {
355+
log.WithField("call", "RunStop").
356+
WithField("partition", envId).Error(err.Error())
357+
}
358+
} else {
359+
log.WithField("call", "RunStop").
360+
WithField("partition", envId).
361+
Debugf("most likely a GRP EOR object for run %d already has been published, doing nothing", grp.runNumber)
331362
}
332363
return
333364
}
334365
return
335366
}
336367

337-
func (p *Plugin) uploadCurrentGRP(varStack map[string]string, envId string, refresh bool) error {
338-
grp := NewGRPObject(varStack)
368+
func (p *Plugin) uploadCurrentGRP(grp *GeneralRunParameters, envId string, refresh bool) error {
339369

340370
if grp == nil {
341371
return errors.New(fmt.Sprintf("Failed to create a GRP object"))

0 commit comments

Comments
 (0)