You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/dev/add_datasources.rst
+28-7Lines changed: 28 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,10 +79,6 @@ Use this as an opportunity to debug your commands so they work as intended befor
79
79
Add Schemas
80
80
===========
81
81
82
-
.. warning ::
83
-
84
-
Sasquatch-backpack version 0.4.0 does not support non-json schemas in its default publishing method. Support is planned, but in the meantime either opt to use the old publish method (PublishMethod.REST_API), or serialize any schema data to json before publishing.
85
-
86
82
`Sasquatch <https://sasquatch.lsst.io>`__ (the wearer of the proverbial backpack), uses `Avro schemas <https://sasquatch.lsst.io/user-guide/avro.html>`__ for data serialization.
87
83
Navigate to your Datasource's folder and create a ``schemas.py`` file for your Datasource.
88
84
Inside, use `pydantic's AvroBaseModel <https://marcosschroh.github.io/dataclasses-avroschema/pydantic/>`__ to create an avro schema.
@@ -104,7 +100,7 @@ Below is a quick sample of usage.
104
100
classMeta:
105
101
"""Schema metadata."""
106
102
107
-
namespace ="$namespace"
103
+
namespace ="Default"
108
104
schema_name ="topic_name_goes_here"
109
105
110
106
Make one such schema for each command or API call you wish to make.
@@ -128,7 +124,7 @@ While not required, giving each entry a unique ID is strongly reccommended to id
128
124
Note 3: Meta
129
125
------------
130
126
The Meta subclass is required, and must contain both namespace and schema_name values.
131
-
The namespace will be replaced with its actual value later on when the file is parsed, so simply keep its value as shown above, in "$thing" format.
127
+
The namespace will be replaced with its actual value later on when the file is parsed, so simply keep its value "Default" as shown above.
132
128
The schema_name, on the other hand, should be hardcoded in.
133
129
134
130
Add Configs
@@ -161,7 +157,7 @@ Add Datasources
161
157
===============
162
158
Now you're finally ready to add Datasources.
163
159
From within your ``scripts.py`` file, for each command you have, make a new Datasource class inheriting from ``sasquatchbackpack.sasquatch.Datasource``.
164
-
These new classes will require two methods: ``get_records()`` and ``get_redis_key()``.
160
+
These new classes will require three methods: ``get_records()``, ``assemble_schema()`` and ``get_redis_key()``.
165
161
166
162
``get_records()`` should call the Datasource's respective ``scripts.py`` function, then return the encoded results in an array.
167
163
This should be surrounded with a "try" like so:
@@ -179,6 +175,31 @@ This should be surrounded with a "try" like so:
179
175
f"A connection error occurred while fetching records: {ce}"
180
176
) from ce
181
177
178
+
``assemble_schema()`` should take one of the list items obtained by get records (or None), and the namespace. This is where that default value above is substituted. This function has two purposes. One is to create a full schema object from a provided record and the other is to provide a compliant boilerplate schema if not provided a record. This is achieved like so:
# Every object in the schema needs to be here, and provided with a boiler plate values
189
+
#eg: "percentage":1.0,
190
+
"namespace"=namespace,
191
+
}
192
+
else:
193
+
schema = {
194
+
"timestamp": record["timestamp"],
195
+
"id": record["id"],
196
+
# Again, Every object in the schema needs to be here, and provided with its record value.
197
+
#eg: "percentage":record["percentage"]
198
+
"namespace": namespace,
199
+
}
200
+
201
+
return CommandnameSchema.parse_obj(data=schema)
202
+
182
203
``get_redis_key()`` can safely return an empty string if your config has set uses_redis to false, and you don't intend to integrate this souce with backpack's redis instance.
183
204
Otherwise, this method should return a unique string structured as such: ``f"{self.topic_name}:uniqueItemIdentifierHere"``.
184
205
This identifier is best suited as an integer id number as stated above in Note #2, however can be anything that uniquely identifies this specific object.
Copy file name to clipboardExpand all lines: docs/dev/publish_methods.rst
-4Lines changed: 0 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,10 +13,6 @@ Direct Connection
13
13
14
14
PublishMethod.DIRECT_CONNECTION is the current default option. With sasquatch and backpack running on the same clusters, it just makes sense to directly connect in. This runs up a connection to sasquatch when publish is called, and sends published data through that tunnel.
15
15
16
-
.. warning ::
17
-
18
-
Sasquatch-backpack version 0.4.0 does not support non-json schemas in its default publishing method. Support is planned, but in the meantime either opt to use the old publish method (PublishMethod.REST_API), or serialize any schema data to json before publishing.
0 commit comments