Skip to content
This repository has been archived by the owner on Jul 25, 2020. It is now read-only.

Functions

David edited this page Apr 29, 2019 · 2 revisions

On PyBuses, Getters, Setters and Deleters are custom functions defined outside PyBuses to work with the data required by the framework. PyBuses run them when required.

Both Stops and Buses have their own Getters, Setters and Deleters, so a total of 6 different groups of functions can be provided.

  • Getters read data from a data source.

  • Setters save data to a data source (usually a source that can be read by a Getter).

  • Deleters remove data from a data source (usually a source that is used as a Setter).

  • Examples of Getters include retrieving Stop info or real-time Buses arriving to a Stop, using an external API.

  • Examples of Setters include saving Stop data (id, name, location) to a local database.

  • Examples of Deleters include removing a previously saved Stop (by a Stop Setter) on a local database.

At least one Stop Getter is required to retrieve Stop info, and one Bus Getter is required to get the buses arriving to a stop.

Order of the functions

For each group of functions (Getters, Setters and Deleters), the functions are defined with a certain order. This should not be random, since when calling to a PyBuses method that must run these functions to get or write data, they will be called on the same order as they were defined. Example scenarios when the order matters:

  • When getting a Stop from a Stop Getter or a Bus list from a Bus Getter: if the Getter function raises a GetterException (because some internal error happened), the next getter will be called, until a Getter retrieves the data successfully or all the Getters are called and failed, in which case a GetterException will be raised by PyBuses.
  • When getting a Stop from an Online Stop Getter, and having PyBuses configured to auto-save Online-found Stops on ONE of the Stop Setters: after retrieving the Stop, it will be saved on the first available/successful Stop Setter.
Clone this wiki locally