Skip to content
This repository has been archived by the owner on Jun 23, 2018. It is now read-only.

Commit

Permalink
Method -> Function (#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanthias committed Mar 24, 2017
1 parent 5fd8d8e commit 481542d
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
20 changes: 10 additions & 10 deletions quick_start/module.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Writing your Module
=========================

NStack Modules contain the methods that can be used on the NStack platform. They are the building blocks which can be used to build workflows and applications.
NStack Modules contain the functions that can be used on the NStack platform. They are the building blocks which can be used to build workflows and applications.

After this tutorial, we will have a simple Python module deployed to our NStack instance, where it can be hooked up to event and data-sources. This module has a single method in it which simply counts the number of characters in some text.
After this tutorial, we will have a simple Python module deployed to our NStack instance, where it can be hooked up to event and data-sources. This module has a single function in it which simply counts the number of characters in some text.

.. note:: Before starting, check that NStack is installed by running ``nstack --version`` in your terminal. If you got information about the version of NStack you have, you're good to go. If that didn't work, check out :doc:`Installation </installation>` again.

Expand Down Expand Up @@ -38,7 +38,7 @@ This is the skeleton of an NStack module. ``nstack.yaml`` is the configuration f

We're going to be concerned with ``nstack.yaml`` and ``service.py``. For a more in-depth look at all these files, refer to :doc:`Module Structure </reference/module_structure>`.

In ``service.py``, there is a ``Service`` class. This is where we would write the methods we want to use on NStack. It is pre-populated with a sample method, ``numChars``, that counts the number of characters in some text.
In ``service.py``, there is a ``Service`` class. This is where we would write the functions we want to use on NStack. It is pre-populated with a sample function, ``numChars``, that counts the number of characters in some text.

.. code:: python
Expand Down Expand Up @@ -70,12 +70,12 @@ In ``service.py``, there is a ``Service`` class. This is where we would write th
api: |
numChars : Text -> Integer
We're going to focus on the ``api`` section, where you tell NStack which of the methods in your ``service.py`` you want to turn into methods on NStack,
We're going to focus on the ``api`` section, where you tell NStack which of the functions in your ``service.py`` you want to turn into functions on NStack,
and their input and output schemas (also known as types).

.. note:: The schema -- or type -- system is a key feature of NStack that lets you define the sort of data your method can take as input, and produce as output. This helps you ensure that your module can be reused and works as intended in production.
.. note:: The schema -- or type -- system is a key feature of NStack that lets you define the sort of data your function can take as input, and produce as output. This helps you ensure that your module can be reused and works as intended in production.

In this instance, we want to expose one method, ``numChars``, which takes ``Text`` and returns an ``Integer``.
In this instance, we want to expose one function, ``numChars``, which takes ``Text`` and returns an ``Integer``.


Step 2: ``build``
Expand All @@ -87,20 +87,20 @@ To build and publish our module on NStack, we use the ``build`` command.
~/demo> nstack build
Building NStack Container module demo. Please wait. This may take some time.
Module demo built successfully. Use `nstack list methods` to see all available methods
Module demo built successfully. Use `nstack list functions` to see all available functions
When we run this, the code in the directory is packaged up and sent to the server, where NStack transforms it into a module.

.. note:: Learn more about how NStack packages and runs your module using containers in the :ref:`Architecture <architecture>` section.

We can check that our ``numChars`` method is live by running the suggested ``nstack list methods`` command:
We can check that our ``numChars`` function is live by running the suggested ``nstack list functions`` command:

.. code:: bash
~/Demo> nstack list methods
~/Demo> nstack list functions
Demo.numChars : Text -> Integer
Now that our ``numChars`` method is live on NStack, we can productionise it by connecting it to input and output data. We do this by attaching it to an event *source* and an event *sink* using NStack's Workflow Language.
Now that our ``numChars`` function is live on NStack, we can productionise it by connecting it to input and output data. We do this by attaching it to an event *source* and an event *sink* using NStack's Workflow Language.

Advanced: Framework Modules
---------------------------
Expand Down
14 changes: 7 additions & 7 deletions quick_start/workflow.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,24 @@ Building your Workflow
=========================

In the previous tutorial, we built and published a Python module `Demo` using NStack.
This module had a single method on it, ``numChars``, which counted the number of characters in some text. Although it has been published, we cannot talk to it until we connect it to a `source` and a `sink`.
This module had a single function on it, ``numChars``, which counted the number of characters in some text. Although it has been published, we cannot talk to it until we connect it to a `source` and a `sink`.
In this tutorial, we're going to do this, and we'll be using an HTTP endpoint as a `source`, and NStack's built-in log as a `sink`. When we're finished, we will be able to send some text to an HTTP endpoint, and see the length of the text in our log.

.. note:: Sources generate data which gets sent to your method, and sinks receive the data which your method outputs. Learn more in :ref:`Concepts<concepts>`
.. note:: Sources generate data which gets sent to your function, and sinks receive the data which your function outputs. Learn more in :ref:`Concepts<concepts>`

Let's first refresh ourselves on what the input and output types of our method were by asking NStack:
Let's first refresh ourselves on what the input and output types of our function were by asking NStack:

.. code:: bash
> nstack list methods
> nstack list functions
Demo.numChars : Text -> Integer
This means that our method can be connected to any source which generates ``Text``, and can write to any sink which can take an ``Integer`` as input.
This means that our function can be connected to any source which generates ``Text``, and can write to any sink which can take an ``Integer`` as input.

One of the sources that NStack provides is ``http``;
if you use this source, NStack sets up an HTTP endpoint which you can send JSON-encoded data to.
As a sink, we are going to use the NStack ``log``,
which is a simple sink for seeing the output from your method.
which is a simple sink for seeing the output from your function.

.. note:: See a list of available sources and sinks in :ref:`Supported Integrations <supported_integrations>`

Expand All @@ -41,7 +41,7 @@ Part Description
=============================================== ===========
``Sources.http<Text> { http_path = "/demo" }`` Use ``http`` as a source, which creates an endpoint on ``/demo``. The ``<Text>`` statement means it can only accept and pass on Text.
``Demo.numChars`` The name of the method which we built.
``Demo.numChars`` The name of the function which we built.
``Sinks.log<Integer>`` Use NStack's log as a sink. The ``<Integer>`` statement means it can only accept Integers.
=============================================== ===========
Expand Down
4 changes: 2 additions & 2 deletions reference/nstack_toolkit.rst
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Option Description
``<primitive>`` The primitive you want to list.
=============== ===========

Shows a list of available primitives. Support primitives are modules, workflows, methods, sources, and sinks.
Shows a list of available primitives. Support primitives are modules, workflows, functions, sources, and sinks.

``delete``
^^^^^^^^^^^^^^^^
Expand All @@ -154,7 +154,7 @@ Option Description
``<module>`` The module's name.
============ ============

Deletes a module (and thus its methods) from NStack.
Deletes a module (and thus its functions) from NStack.


``logs``
Expand Down

0 comments on commit 481542d

Please sign in to comment.