Functions

Flexible Intake Functions let you run code in the platform, in response to certain events or triggers, without needing any client-side script.

Functions are useful when you want the platform to behave in a specific way in response to internal or external events, or when you want to add your own code to be executed on demand (typically by yourself).

With the Flexible Intake Functions, you just upload your code and add the triggers that you would like it to execute. Users are able to define data container-level lambda functions (platform Lambda functions) that are executed on certain events:

  • CRUD Functions for files and metadata: When files are created, read, updated or deleted.

    E.g. every time you upload one of your astrophysics-related files to a certain data container:

    • E.g.: Every time you upload one of your photographs:

      • Extract the date from the file name to the metadata catalogue, so it is searchable using the web interface or the API,

      • Calculate each file integrity and

      • Tag images that contain faces

  • Periodic functions: Every minute, hour and day.

    E.g.: Webhooks to other systems

  • Executed-by-demand functions: When the user selects files using the GUI or launched using the API.

    E.g.: For fetch.txt files containing a manifest of files to download, make Flexible Intake to download them and place them inside the container.

A python library to make using the API easier and more convenient is available: library and its documentation. This library can be used in Functions, Jupyter Notebooks and in your own scripts.

How to create a Flexible Intake Function

  1. Go to Configuration and then to Functions:

  1. Select Add function:

  1. Give your function a meaningful name and description (both elements will be shown in the interface to the users, so make it sure you keep it short and concise). Enable it.

  2. In the Code tab, you can add the code you would like the platform to execute. Check the Functions code gallery to find examples. Introduce a "handler" that will be the unique short name for your function.

  3. Go to the triggers section and select the events that you would like to execute the function.

  4. Go to the parameters section and define the parameters that the function will accept. These parameters are only for on-demand functions, in which the user will be requested to provide certain parameters when calling the function.

  5. Select Create

Function's code

We have created a Python library that simplifies many actions and makes your programming easier when creating a function.

A python library to make using the API easier and more convenient is available: library and its documentation. This library can be used in Functions, Jupyter Notebooks and in your own scripts.

For example, lets say you would like to create a function that hashes your files with a new algorithm you would like to use.

First, you should initialize your function, loading the LIBNOVA Flexible Intake libraries:

If your code is going to be called from a Flexible Intake Function, you will receive some parameters from Flexible Intake every time your function is called. This variable is initialized in the following way:

Depending on the function type, the structure you receive can change, but usually you can find the following:

Every function executes in relation to an (Execution) Job, that is really useful for logging the execution progress. You should initialize it with:

And you can log to it using:

The JobMessage.JobMessageType defines the type of message. You can see a list of the available types in the method documentation.

And then, you would usually have your payload. In this example:

And finally, we must let Flexible Intake know that our function has finished, with the result status:

The full code sample:

Last updated

Was this helpful?