Skip to content

Commit

Permalink
update to docs on send
Browse files Browse the repository at this point in the history
  • Loading branch information
ssadedin committed Jan 15, 2018
1 parent 9ac1c7b commit 465f264
Showing 1 changed file with 75 additions and 8 deletions.
83 changes: 75 additions & 8 deletions docs/Language/Send.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,35 @@

Sends the specified content through the specified communication channel.

The first form sends the content using the defaults that are inferred from the configuration of the channel or derived directly from the content itself. The second form allows specification of lower level details of how the content should be sent and the message.

The purpose of `send` is to enable explicitly sending content such as small reports and status messages as part of the flow of your pipeline. The `send` command can occur inside pipeline stages that perform other processing, or stand alone as part of a dedicated pipeline stage.

The content can be specified in three different ways. The first option simply specifies a literal text string that is used as the message directly. Note that the text string *must* appear within curly braces. It will be lazily evaluated just prior to sending. The `html` option allows creation of HTML content programmatically. The body of the closure (that is, inside the curly braces) is passed a [Groovy MarkupBuilder](http://groovy.codehaus.org/Creating+XML+using+Groovy's+MarkupBuilder). This can be used to create HTML that forms the body of an HTML email.

The final form allows specification of a template. The template should end with an extension appropriate to the content type (for example, to send an HTML email, make sure the template ends with ".html"). The template file is processed as a [Groovy Template](http://groovy.codehaus.org/Groovy+Templates) which allows references to variables using the normal `$` syntax, `${variable}` form as well as complete Groovy programmatic logic within `<% %>` and `<%= %>` blocks.
The first form sends the content using the defaults that are inferred from the
configuration of the channel or derived directly from the content itself. The
second form allows specification of lower level details of how the content
should be sent and the message.

The purpose of `send` is to enable explicitly sending content such as small
reports and status messages as part of the flow of your pipeline. The `send`
command can occur inside pipeline stages that perform other processing, or
stand alone as part of a dedicated pipeline stage.

The content can be specified in three different ways. The first option simply
specifies a literal text string that is used as the message directly. Note that
the text string *must* appear within curly braces. It will be lazily evaluated
just prior to sending. The `html` option allows creation of HTML content
programmatically. The body of the closure (that is, inside the curly braces) is
passed a [Groovy MarkupBuilder](http://groovy.codehaus.org/Creating+XML+using+Groovy's+MarkupBuilder).
This can be used to create HTML that forms the body of an HTML email.

The next form allows specification of a template. The template should end with
an extension appropriate to the content type (for example, to send an HTML
email, make sure the template ends with ".html"). The template file is
processed as a [Groovy Template](http://groovy.codehaus.org/Groovy+Templates)
which allows references to variables using the normal `$` syntax, `${variable}`
form as well as complete Groovy programmatic logic within `<% %>` and `<%= %>`
blocks.

A `json` utility method is available to format data as JSON. The `json` method
accepts a JSON-encodable object (eg: groovy/java list, map, string, integer, etc),
which is encoded to JSON and then sent as the body of the message.

*Note*: a common scenario is to terminate a branch of a pipeline due to a failure or exceptional situation and to send a status message about that. To make this convenient, the [succeed](Language/Succeed) and [fail](Language/Fail) commands can accept the same syntax as `send`, but also have the effect of terminating the execution of the current pipeline branch with a corresponding status message.

Expand Down Expand Up @@ -56,6 +78,51 @@ The final form allows specification of a template. The template should end with

**Send a message based on a template using Gmail, and attach the first output as a file**
```groovy
send report("report-template.html") to channel: gmail, file: output1.txt
```

**Send a JSON message to an ActiveMQ Queue**

To configure the connection, configure an activemq section in the `notifications`, eg:

```
notifications {
analysis_finished_queue {
type='activemq'
queue='analysis_complete' // the actual activemq queue name
brokerURL='tcp://127.0.0.1:61616'
events=''
}
}
```

Notice we disable other events from being forwarded so that we only receive messages
explicitly sent through the connection.

```groovy
send json(
sample: sample,
sex: "Male"
batch: batch,
run_id: analysis_id
) to analysis_finished_queue
```

In the above, we take advantage of the Groovy abbreviated syntax for
specifying a Map as an argument to a function. The equivalent is:

```groovy
send json(
[
sample: sample,
sex: "Male"
batch: batch,
run_id: analysis_id
]
) to analysis_finished_queue
```





0 comments on commit 465f264

Please sign in to comment.