Summary: An overview of the types of scheduled queries and how to work with custom scheduled queries using various API methods.
With Alooma there are two types of queries, both of which are scheduled: Consolidation and Custom scheduled queries. For more information about queries see Queries. Here, we'll focus on scheduled queries.
You could use a scheduled query to do something like take a snapshot of a table every night to create a log table.
Just like with all other API work, it all begins with authenticating and getting an API instance. Once you have an API Instance, you can get a list of scheduled queries as well as create/schedule and delete them by using the methods below.
get_scheduled_queries() to return a list of scheduled queries. You can also retrieve the list of any scheduled queries that did not run successfully on the last attempt.
api.get_scheduled_queries() # in error state api.get_scheduled_queries_in_error_state()
schedule_query() to create a custom scheduled query specifying the event type, query, and either the frequency or the schedule, but not both. You can use a cron-like string for the value of
# # Creating a Scheduled Query # # all queries must tie to an event type, even if they do not relate EVENT_TYPE = '<test_event>' QUERY = """ CREATE VIEW example AS SELECT * FROM my_table; """ ## These fields control query run times (only 1 can be used/specified) # Frequency takes an integer value, re-run query X hours after last run FREQUENCY=24 # run_at takes a Cron-like string (i.e. "0 * * * *") RUN_AT=None api.schedule_query(EVENT_TYPE, QUERY, frequency=FREQUENCY, run_at=RUN_AT)
Snowflake users will need to replace single quotes (') in the query string with two dollar signs ($$) as explained in Dollar-quoted String Constants, here: https://docs.snowflake.net/manuals/sql-reference/data-types-text.html#dollar-quoted-string-constants