bionode-watermill icon indicating copy to clipboard operation
bionode-watermill copied to clipboard

Refactor task definition

Open tiagofilipe12 opened this issue 7 years ago • 3 comments

Current implementation on task definition by the user is somehow javascript dependent. Example:

const gunzipIt = task({
    input: '*_genomic.fna.gz',
    output: '*.fa',
    params: { output: 'uncompressed.fa' }
  }, ({ params, input}) => `gunzip -c ${input} > ${params.output}`
)

It would be nice to abstract the user from this object, function task shape, to something more user-friendly. For example:

const gunzipIt = { task:
  { input:  '*_genomic.fna.gz',
    output: 'uncompressed.fa',
    function: '`gunzip -c ${input} > ${params.output}`'
  }
}

Notice that I removed params.output, because that can be tricky for the user to understand, and instead this check of the output pattern could be done by the api. This could be integrated with #74 .

tiagofilipe12 avatar Aug 23 '17 10:08 tiagofilipe12

Why

'`gunzip -c ${input} > ${params.output}`'

instead of

`gunzip -c ${input} > ${params.output}`

?

Except then input and params will be undefined: I think we will always still need something with

func: function(resolvedProps) {
  return `gunzip -c ${resolvedProps.input} > ${params.output}`
}

and then, the change is basically just moving the operationCreator from the second param to a property of the props object. Which I am OK with as a change -

const gunzipIt = {
  input:  '*_genomic.fna.gz',
  output: 'uncompressed.fa',
  operation: ({ params, input}) => `gunzip -c ${input} > ${params.output}`
}

(maybe don't need to nest under task? - except for orchestrators?)

One benefit of having the task function is that you still then get an invocableTask which can be used to manually orchestrate tasks or anything.

Either way - I think this is less priority than #74 and probably mostly a style change, unless #74 brings up changes that require changing it here as well.

It feels like to me this simply just changes (propsObject, operationCreator) into (propsObjectWithOperationCreator) since the task function is still needed to parse the definition into something that runs a task lifecycle - invocableTask

thejmazz avatar Aug 24 '17 01:08 thejmazz

I said:

'`gunzip -c ${input} > ${params.output}`'

because internally maybe it can be converted into this:

func: function(resolvedProps) {
  return `gunzip -c ${resolvedProps.input} > ${params.output}`
}

but your suggestion is also nice, where you replace (propsObject, operationCreator) by (propsObjectWithOperationCreator).

And yes, this is just styling to make it easier for users outside the scope of JS to use the tool.

tiagofilipe12 avatar Aug 24 '17 07:08 tiagofilipe12

https://blog.jcoglan.com/2011/03/11/promises-are-the-monad-of-asynchronous-programming/

tiagofilipe12 avatar Aug 25 '17 16:08 tiagofilipe12