@@ -22,6 +22,7 @@ import (
22
22
"go.opentelemetry.io/otel/trace"
23
23
24
24
v1types "github.com/metal-toolbox/conditionorc/pkg/api/v1/types"
25
+ "github.com/metal-toolbox/rivets/condition"
25
26
rctypes "github.com/metal-toolbox/rivets/condition"
26
27
rkv "github.com/metal-toolbox/rivets/events/pkg/kv"
27
28
"github.com/metal-toolbox/rivets/events/registry"
@@ -165,21 +166,11 @@ func (r *Routes) conditionQueuePop(c *gin.Context) (int, *v1types.ServerResponse
165
166
}
166
167
}
167
168
168
- // create Task entry
169
- task := & rctypes.Task [any , any ]{
170
- StructVersion : rctypes .TaskVersion1 ,
171
- ID : cond .ID ,
172
- Kind : conditionKind ,
173
- State : rctypes .Pending ,
174
- Status : st ,
175
- WorkerID : controllerID .String (),
176
- Asset : & rctypes.Asset {ID : serverID },
177
- TraceID : trace .SpanFromContext (ctx ).SpanContext ().TraceID ().String (),
178
- SpanID : trace .SpanFromContext (ctx ).SpanContext ().SpanID ().String (),
179
- Parameters : cond .Parameters ,
180
- Data : json .RawMessage (`{"empty": true}` ), // placeholder value
181
- Fault : cond .Fault ,
182
- }
169
+ // setup task to be published
170
+ task := condition .NewTaskFromCondition (cond )
171
+ task .WorkerID = controllerID .String ()
172
+ task .TraceID = trace .SpanFromContext (ctx ).SpanContext ().TraceID ().String ()
173
+ task .SpanID = trace .SpanFromContext (ctx ).SpanContext ().SpanID ().String ()
183
174
184
175
if err := r .kvPublishTask (
185
176
ctx ,
@@ -188,6 +179,7 @@ func (r *Routes) conditionQueuePop(c *gin.Context) (int, *v1types.ServerResponse
188
179
conditionKind ,
189
180
task ,
190
181
true ,
182
+ false ,
191
183
); err != nil {
192
184
r .logger .WithField ("condition.id" , cond .ID ).WithError (err ).Info ("task KV publish error" )
193
185
@@ -409,7 +401,7 @@ func (r *Routes) kvPublishStatusValue(
409
401
controllerID registry.ControllerID ,
410
402
conditionKind rctypes.Kind ,
411
403
newSV * rctypes.StatusValue ,
412
- create bool ,
404
+ create ,
413
405
onlyTimestamp bool ,
414
406
) error {
415
407
statusKV , err := status .GetConditionKV (conditionKind )
@@ -763,15 +755,22 @@ func (r *Routes) taskPublish(c *gin.Context) (int, *v1types.ServerResponse) {
763
755
attribute.KeyValue {Key : "serverId" , Value : attribute .StringValue (c .Param ("uuid" ))},
764
756
attribute.KeyValue {Key : "conditionKind" , Value : attribute .StringValue (c .Param ("conditionKind" ))},
765
757
attribute.KeyValue {Key : "conditionID" , Value : attribute .StringValue (c .Param ("conditionID" ))},
758
+ attribute.KeyValue {Key : "timestampUpdate" , Value : attribute .StringValue (c .Request .URL .Query ().Get ("ts_update" ))},
766
759
)
767
760
defer span .End ()
768
761
769
762
var task rctypes.Task [any , any ]
770
- if err := c .ShouldBindJSON (& task ); err != nil {
771
- r .logger .WithError (err ).Warn ("unmarshal Task payload" )
763
+ var onlyTimestampUpdate bool
772
764
773
- return http .StatusBadRequest , & v1types.ServerResponse {
774
- Message : "invalid Task payload: " + err .Error (),
765
+ if c .Request .URL .Query ().Get ("ts_update" ) == "true" {
766
+ onlyTimestampUpdate = true
767
+ } else {
768
+ if err := c .ShouldBindJSON (& task ); err != nil {
769
+ r .logger .WithError (err ).Warn ("unmarshal Task payload" )
770
+
771
+ return http .StatusBadRequest , & v1types.ServerResponse {
772
+ Message : "invalid Task payload: " + err .Error (),
773
+ }
775
774
}
776
775
}
777
776
@@ -829,6 +828,7 @@ func (r *Routes) taskPublish(c *gin.Context) (int, *v1types.ServerResponse) {
829
828
conditionKind ,
830
829
& task ,
831
830
false ,
831
+ onlyTimestampUpdate ,
832
832
); err != nil {
833
833
return http .StatusInternalServerError , & v1types.ServerResponse {
834
834
Message : "Task publish error: " + err .Error (),
@@ -873,7 +873,15 @@ func (r *Routes) registerRegistryKVHandle() error {
873
873
}
874
874
875
875
// Publish implements the ConditionTaskRepository interface, it transparently publishes the given json.RawMessage to the KV
876
- func (r * Routes ) kvPublishTask (ctx context.Context , serverID , conditionID string , conditionKind rctypes.Kind , task * rctypes.Task [any , any ], create bool ) error {
876
+ func (r * Routes ) kvPublishTask (
877
+ ctx context.Context ,
878
+ serverID ,
879
+ conditionID string ,
880
+ conditionKind rctypes.Kind ,
881
+ task * rctypes.Task [any , any ],
882
+ create ,
883
+ onlyTimestamp bool ,
884
+ ) error {
877
885
_ , span := otel .Tracer (pkgName ).Start (
878
886
ctx ,
879
887
"controller.Publish.KV.Task" ,
@@ -947,24 +955,20 @@ func (r *Routes) kvPublishTask(ctx context.Context, serverID, conditionID string
947
955
return failed (errors .Wrap (err , "Task object deserialize error" ))
948
956
}
949
957
950
- // verify conditionID matches before update
951
- if currTask .ID .String () != conditionID && ! rctypes .StateIsComplete (currTask .State ) {
952
- msg := fmt .Errorf (
953
- "existing Task object %s in in-complete state, does not match conditionID: %s, must be purged before proceeding" ,
954
- currTask .ID .String (),
955
- conditionID ,
956
- )
957
-
958
- return failed (msg )
958
+ if onlyTimestamp {
959
+ currTask .UpdatedAt = time .Now ()
960
+ } else {
961
+ if err := currTask .Update (task ); err != nil {
962
+ return failed (err )
963
+ }
959
964
}
960
965
961
- task .UpdatedAt = time .Now ()
962
- taskJSON , err := task .Marshal ()
966
+ currTaskJSON , err := currTask .Marshal ()
963
967
if err != nil {
964
968
return failed (err )
965
969
}
966
970
967
- if _ , err := taskKV .Update (key , taskJSON , curr .Revision ()); err != nil {
971
+ if _ , err := taskKV .Update (key , currTaskJSON , curr .Revision ()); err != nil {
968
972
return failed (err )
969
973
}
970
974
0 commit comments