Watcher: Multiple transforms

Hi,

I was wondering if it is possible to use multiple transforms in a watch?

For example, i want to convert two values to GB from Bytes.

"transform" : {
    "script" : "return [ 'max_queue_size' : (ctx.payload.pipelines.main.queue.capacity.max_queue_size_in_bytes / 1024 / 1024 / 1024) ]"
  },

That works but the in the same watch i want to do the same conversion for 'ctx.payload.pipelines.main.queue.capacity.queue_size_in_bytes'.

In my mind i would then have to do something like this:

"transform" : {
    "script" : "return [ 'max_queue_size' : (ctx.payload.pipelines.main.queue.capacity.max_queue_size_in_bytes / 1024 / 1024 / 1024) ]",
               "return [ 'current_queue_size' : (ctx.payload.pipelines.main.queue.capacity.queue_size_in_bytes / 1024 / 1024 / 1024) ]
  },

However, that wont save the file and when i try to simulate the file i get the following error:

[parse_exception] could not parse watch [_inlined_]. unexpected field [0]

How can i achieve this?

you can do multiple transforms by returning a data structure that can contain multiple values, i.e. a map in your transform

def map = [:]
map.max_queue_size = ...;
map.current_queue_size = ...;
return map

hope this helps

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.