DataStore¶
-
class
glados.datastore.
DataStore
(host, username, password, port=5432, database='glados')[source]¶ Bases:
object
DataStore is how GLaDOS stores async data.
- Parameters
host (
str
) – postgres host.username (
str
) – postgres username.password (
str
) – postgres password.port (
int
) – postgres port.database (
str
) – postgres database to use.
-
create_table
(tables=None, force=False)[source]¶ Create the table.
If you set force to True then it will drop the existing tables and then recreate them. ALL DATA WILL BE LOST
- Parameters
tables (
Optional
[List
[str
]]) – only take action on these tables. If None, then take action on all tablesforce (
bool
) – drop existing tables and rebuild. (default: False)
- Return type
NoReturn
-
drop_table
(table='interactions', force=False)[source]¶ Drop the GLaDOS table so that it can be re-created.
- Parameters
table (
str
) – table name to use.force (
bool
) – if True will fill force drop the table without checks.
- Return type
NoReturn
-
find_by_id
(interaction_id, session)[source]¶ Find an interaction by interaction_id.
- Parameters
interaction_id (
str
) – interaction ID to findsession (
Session
) – session to be used
- Return type
-
find_interaction_by_channel_ts
(channel, ts, session)[source]¶ Find the interaction in the datastore by channel and message ts.
- Parameters
channel (
str
) – channel of the interaction youre looking forts (
datetime
) – ts of the interaction you are looking forsession (
Session
) – session to be used
- Raises
ReferenceError – There were more than one interaction that matched the channel and message_ts
- Return type
Optional
[DataStoreInteraction
]
-
insert_interaction
(interaction, session)[source]¶ Insert an interaction object into the database.
- Parameters
interaction (
DataStoreInteraction
) – The row to be insertedsession (
Session
) – session to be used
- Return type
NoReturn
-
link_to_message
(interaction_id, channel, ts, session)[source]¶ Link to message by setting message ts and channel.
- Parameters
interaction_id (
str
) – interaction ID to linkchannel (
str
) – channel to link interaction tots (
datetime
) – ts to link interaction tosession (
Session
) – session to be used
- Return type
NoReturn
-
link_to_message_response
(interaction_id, message_response, session)[source]¶ Add info from the Slack message into the database for the interaction.
- Parameters
interaction_id (
str
) – The interaction ID that was returned on adding the message to the database.message_response (
dict
) – The raw message response from slack. The channel and ts will be pulled from this.session (
Session
) – session to be used
- Return type
NoReturn
-
table_exists
(table='interactions')[source]¶ Check to see if the GLaDOS table is found in postgres.
- Parameters
table (
str
) – table name to use.- Return type
bool
-
class
glados.datastore.
DataStoreInteraction
(**kwargs)[source]¶ Bases:
sqlalchemy.ext.declarative.api.Base
DataStoreInteraction represents a row in the datastore. This is used to update data in the datastore.
-
interaction_id
¶ This is the primary key of the datastore. This is the ID of the entry in the datastore.
- Type
str
-
ts
¶ This is the time the row was put into the database.
- Type
datetime
-
bot
¶ This is the name of the bot it should use when completing followup actions.
- Type
str
-
data
¶ Any extra data stored with the interaction. This is a JSON blob.
- Type
dict
-
message_channel
¶ The channel that this interaction was sent to.
- Type
str
-
message_ts
¶ The message timestamp when this interaction was sent.
- Type
datetime
-
ttl
¶ How long this interaction should live for.
- Type
int
-
followup_ts
¶ When should the follow up action happen.
- Type
datetime
-
followup_action
¶ The action name to execute when following up. If None then no action will happen.
- Type
str
-
cron_followup_action
¶ The action name to execute on a normal cron schedule like every 5 min. If None then no action will happen.
- Type
str
-
followed_up
¶ This is the time when the action was followed up at. If it has not happened yet this value will be None.
- Type
datetime
A simple constructor that allows initialization from kwargs.
Sets attributes on the constructed instance using the names and values in
kwargs
.Only keys that are present as attributes of the instance’s class are allowed. These could be, for example, any mapped columns or relationships.
-