func()

in server/internal/async/hooks.go [69:87]


func (h *OperationStatusHook) AfterRun(ctx context.Context, op opbus.ApiOperation, err error) error {
	req := op.GetOperationRequest()
	if err != nil {
		// on error set as pending
		pendingOperationStatus := oc.Status_PENDING.String()
		err := h.updateEntityDatabase(ctx, pendingOperationStatus, req.EntityId, req.EntityType)
		if err != nil {
			return fmt.Errorf("Something went wrong updating the entity database of entity with id: %s and type: %s to PENDING status: %s", req.EntityId, req.EntityType, err)
		}
	} else {
		// no nil error set as complete
		inProgressOperationStatus := oc.Status_COMPLETED.String()
		err := h.updateEntityDatabase(ctx, inProgressOperationStatus, req.EntityId, req.EntityType)
		if err != nil {
			return fmt.Errorf("Something went wrong updating the entity database of entity with id: %s and type: %s to COMPLETED status: %s", req.EntityId, req.EntityType, err)
		}
	}
	return nil
}