Explanation

This section describes how to add an app to Giraffe and make it available to the right people.

Once you've designed an app, and set default featureCategories, defaultParams, etc. you need to configure it to run. All apps are run through Google's PubSub service. This means that queuing your app's tasks and scaling your app with multiple workers is taken care of by Giraffe.

<aside> ❓ If your app requires direct access to the Giraffe API (bypassing PubSub), that is possible too. Please email [email protected] for assistance.

</aside>

The apps added to Giraffe are able to be run on any computer connected to the internet. When a user runs an app, the following sequence of events takes place:

  1. Giraffe publishes a "message" to the PubSub topic for the App.
  2. Google PubSub sends the message to the first available subscriber. The subscriber is (one of) the app developer's server/computer/worker. If many apps are being run in a short time, they will be queued and sent to the subscriber(s) one at a time.
    1. The message that the subscriber receives contains:
      1. A link to GET the app payload, which is the project data that the app requires to run.
      2. A link to POST the app's result once it has been completed.
      3. The App's name. This is useful if you want the same worker(s) to process a number of apps.
  3. The subscriber runs the app and returns the result.
  4. Giraffe updates the project data based on the result from the app. The Giraffe user that ran the app can see it completed.

<aside> ℹ️ Giraffe leverages the Google cloud pubsub system. You can read about it here. https://cloud.google.com/pubsub/docs/overview.

</aside>

This is how the data flows.

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/8978d6c0-6c3d-4a87-9771-46749470e08f/Untitled.png

Sample Script for Subscriber

The python script included here requires a credentials.json which allows the server to subscribe to the topic. The python script then uses the name of the app to fire a Grasshopper script of the same name. The python script saves the giraffeModel in a folder specified by the user and the GH script reads it in from that folder. Finally the python script POSTs the GH output from a folder to the Giraffe endpoint specified in the pubsub message.

At the top of main.py set the following variables in order for you server to start.

SCRIPT_DIR = 'C:\\\\Users\\\\Public\\\\gh_load'  # SCRIPT TO GO HERE
INPUT_PATH = 'C:\\\\Users\\\\Public\\\\gh_load\\\\gmodel.json' # FOLDER TO LOAD GMODEL (SET AT START OF GH SCRIPT)
OUTPUT_PATH = 'C:\\\\Users\\\\Public\\\\gh_dump\\\\output.json' # FOLDER TO DUMP OUTPUT (SET AT END OF GH SCRIPT)
RESTART_PATH = 'C:\\\\Users\\\\Public\\\\test_plugin\\\\start_subscribe.bat' #bat file that references credentials json
TOPIC_NAME = 'YOUR TOPIC NAME'

run start_subscribe.bat to load in the credentials and start the listener.