Queries
Run feature pipelines on a schedule
When features are coming from a single SQL file, or a single resolver, you can use resolver crons to keep your online and offline stores up to date.
However, when features are chained together, or when you need to run a feature pipeline on a schedule, you can use scheduled queries.
Scheduled queries let you run an offline query on a schedule, and persist the results in the online and/or offline feature stores.
To create a scheduled query, make a ScheduledQuery object somewhere in your code. Crontabs can be used to specify the schedule in the UTC timezone.
from chalk import ScheduledQuery
ScheduledQuery(
name="enrich-transactions",
schedule="0 0 * * *",
output=[Transaction.clean_name, Transaction.category],
store_online=True,
store_offline=True,
)
When you run chalk apply, Chalk creates the scheduled query.
In the dashboard, open Offline > Schedules. The Definitions tab lists your scheduled queries with each
one’s schedule, latest run, and next run, and the Scheduled query runs tab lists the runs
themselves. Click a run’s ID to open the run, and use its Logs tab to see its logs. Click a
scheduled query’s name to open its page, which has Overview, Run history,
Scheduled run configuration, and Debug tabs.
By default, scheduled queries use incrementalization to only ingest data which
has been updated since the last run. You can also set a resolver to use as the
source of the incrementalization. For example, if you were enriching financial
transaction data, you might use the transactions.chalk.sql resolver as the
source of incrementalization.
from chalk import ScheduledQuery
ScheduledQuery(
name="enrich-transactions",
schedule="0 0 * * *",
output=[Transaction.clean_name, Transaction.category],
store_online=True,
store_offline=True,
incremental_resolvers="transactions",
)
To get notified when a scheduled query fails, create a metric chart monitor with these settings:
failureSee Monitors for how monitors, incidents, and alert channels work.
Additionally, you can export metrics about scheduled query executions to your observability tools.
The cron_run_request metric (see metrics export documentation) tracks the number of times a scheduled
query was executed, with tags for success/failure status. This allows you to monitor scheduled query reliability
and alert when executions fall below expected thresholds in your preferred monitoring system.
By default, scheduled query runs are picked up by the Job Queue Consumer. To see your
Job Queue Consumer resource configurations, check the Job Queue Consumer service under
Resources in the dashboard. To customize the resources allocated to runs for a specific
scheduled query, set the resource configuration under the Scheduled run configuration tab on
the scheduled query’s page in the dashboard.