Schedule Kumo Native App & Batch Predictions

View as Markdown

0. Grant yourself read access to Kumo tables 

Because Kumo may create new tables or update existing ones during prediction runs, grant yourself (or a reader role) access to existing and future tables in the destination schema.

Replace placeholders:

  • TARGET_DB / TARGET_SCHEMA → where your BP writes prediction/output tables
  • MY_ROLE → the role you use to read those outputs (can be ACCOUNTADMIN, or any role)
1-- you must have these to "see" the objects
2GRANT USAGE ON DATABASE TARGET_DB TO ROLE MY_ROLE;
3GRANT USAGE ON SCHEMA  TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;
4
5-- read existing tables (one-time for what already exists)
6GRANT SELECT ON ALL TABLES IN SCHEMA TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;
7
8-- read all future tables (so you don't have to grant every run)
9GRANT SELECT ON FUTURE TABLES IN SCHEMA TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;

1. Define Procedures

Create two small procedures you can call from the notebook to safely start and stop the Kumo app.

Replace:

  • MY_DB.MY_SCHEMA → where to store these procedures (e.g., KUMO.AUTOMATION)
  • MY_APP → your installed app name (e.g., KUMO_SPCS_RELEASE_INTERNAL)
  • MY_USER_SCHEMA → schema used when installing the app
1-- Idempotent START_APP
2CREATE OR REPLACE PROCEDURE MY_DB.MY_SCHEMA.START_APP()
3RETURNS STRING
4LANGUAGE JAVASCRIPT
5EXECUTE AS CALLER
6AS
7$$
8function run(sql){ snowflake.execute({sqlText: sql}); }
9try {
10 // If this resolves, the app is already running
11 run("CALL IDENTIFIER('MY_APP.PROCEDURES.GET_END_POINT')('MY_USER_SCHEMA')");
12 return 'App already running; no action taken.';
13} catch (e) {
14 // Not running -> start it
15 run("CALL IDENTIFIER('MY_APP.PROCEDURES.START_APP')('MY_USER_SCHEMA')");
16 return 'App start initiated.';
17}
18$$;
19
20-- Idempotent STOP_APP
21CREATE OR REPLACE PROCEDURE MY_DB.MY_SCHEMA.STOP_APP()
22RETURNS STRING
23LANGUAGE JAVASCRIPT
24EXECUTE AS CALLER
25AS
26$$
27function run(sql){ snowflake.execute({sqlText: sql}); }
28try {
29 // Try to stop; if already stopped, the call may error — we swallow it
30 run("CALL IDENTIFIER('MY_APP.PROCEDURES.SHUTDOWN_APP')('MY_USER_SCHEMA')");
31 return 'App stop initiated.';
32} catch (e) {
33 return 'App already stopped or stop not needed; no action taken.';
34}
35$$;

2. Use these in your Kumo BP SDK snippet

If you haven’t set up the SDK yet, follow the setup guide here

Rules:

  • Call START_APP() first (very first command).
  • Run your BP pipeline with non_blocking = False so the notebook waits for completion.
  • Call STOP_APP() last (very last command), so the app shuts down after the job.

Example notebook flow

SQL cell — start app (first line):

1CALL MY_DB.MY_SCHEMA.START_APP();

Python cell — Kumo BP SDK (make sure non_blocking=False):

1import kumoai
2
3# Gather artifacts
4pquery = kumoai.PredictiveQuery.load_from_training_job("trainingjob-...")
5graph = pquery.graph
6
7# Create a prediction table from the predictive query:
8prediction_table = pquery.generate_prediction_table()
9
10# Generate predictions:
11trainer = kumoai.Trainer.load("trainingjob-...")
12prediction_job = trainer.predict(
13 graph,
14 prediction_table,
15 non_blocking = False # <<< Make sure this is False so the notebook waits
16)

SQL cell — stop app (last line):

1CALL MY_DB.MY_SCHEMA.STOP_APP();

3) Schedule the Containerized Notebook

  1. Open your containerized notebook in Snowflake.
  2. Click Schedule.
  3. Set your CRON/time zone and save

CRON examples

  • Every 3 hours (top of hour):
    USING CRON 0 */3 * * * America/Chicago
  • Daily at 7:00 AM:
    USING CRON 0 7 * * * America/Chicago
  • Daily at 8:00 PM:
    USING CRON 0 20 * * * America/Chicago