Skip to content

Commit

Permalink
Merge pull request #576 from TOMToolkit/fix/docs
Browse files Browse the repository at this point in the history
Fix/docs
  • Loading branch information
jchate6 authored Oct 31, 2022
2 parents 3705b16 + c034e99 commit c4fd586
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
19 changes: 13 additions & 6 deletions docs/brokers/create_broker.rst
Original file line number Diff line number Diff line change
Expand Up @@ -125,28 +125,35 @@ alerts and targets.
``fetch_alerts`` Class Method
-----------------------------

`fetch_alerts` is used to query the remote broker, and return an iterator
of results depending on the parameters passed into the query, so that
these results may be displayed on the query results page. In our case, `fetch_alerts`
`fetch_alerts` is used to query the remote broker, and return both an iterator
of results and any broker feedback received depending on the parameters passed into the query, so that
any results or feedback (such as error messages) may be displayed on the query results page. In our case, `fetch_alerts`
will only filter on name, but this can be easily extended to other query parameters.

.. code-block:: python
@classmethod
def fetch_alerts(clazz, parameters):
broker_feedback = ''
response = requests.get(broker_url)
response.raise_for_status()
test_alerts = response.json()
return iter([alert for alert in test_alerts if alert['name'] == parameters['target_name']])
alert_list = []
try:
alert_list = [alert for alert in test_alerts if alert['name'] == parameters['target_name']]
except KeyError: # We want to catch error messages returned from the Broker and pass them on as feedback.
broker_feedback = test_alerts
return iter(alert_list), broker_feedback
**Why an iterator?** Because some alert brokers work by sending streams, not fully
evaluated lists. This simple example broker could easily return a list (in fact we
are coercing the list into an iterator!) but that would not work in the model
where a broker is sending an unending stream of alerts.

Our implementation will get a response from our test broker source, check that our
request was successful, and return a iterator of alerts whose name field matches the
name passed into the query.
request was successful, and if so, return a iterator of alerts whose name field matches the
name passed into the query. If the keyword 'name' isn't present in the alert, we pass the results
as feedback.

``to_generic_alert`` Class Method
---------------------------------
Expand Down
3 changes: 3 additions & 0 deletions tom_alerts/brokers/lasair.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ class LasairBroker(GenericBroker):
"""
The ``LasairBroker`` is the interface to the Lasair alert broker. For information regarding the query format for
Lasair, please see https://lasair-ztf.lsst.ac.uk/.
Requires a LASAIR_TOKEN in settings.py.
See https://lasair-ztf.lsst.ac.uk/api for details about how to acquire an authorization token.
"""

name = 'Lasair'
Expand Down

0 comments on commit c4fd586

Please sign in to comment.