> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/sdgm/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/sdgm/_mcp/server.

# Schedule Kumo Native App and Batch Predictions

> This guide walks through setting up Snowflake Tasks and Procedures to automatically: run a Snowflake Notebook at the scheduled time, start the Kumo App and trigger a Batch Prediction job, and after the job finishes, stop the Kumo App.

## **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)

```sql
-- you must have these to "see" the objects
GRANT USAGE ON DATABASE TARGET_DB TO ROLE MY_ROLE;
GRANT USAGE ON SCHEMA  TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;

-- read existing tables (one-time for what already exists)
GRANT SELECT ON ALL TABLES IN SCHEMA TARGET_DB.TARGET_SCHEMA TO ROLE MY_ROLE;

-- read all future tables (so you don't have to grant every run)
GRANT 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 (for example, `KUMO.AUTOMATION`)
> * `MY_APP` → your installed app name (for example, `KUMO_SPCS_RELEASE_INTERNAL`)
> * `MY_USER_SCHEMA` → schema used when installing the app

```sql
-- Idempotent START_APP
CREATE OR REPLACE PROCEDURE MY_DB.MY_SCHEMA.START_APP()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
function run(sql){ snowflake.execute({sqlText: sql}); }
try {
  // If this resolves, the app is already running
  run("CALL IDENTIFIER('MY_APP.PROCEDURES.GET_END_POINT')('MY_USER_SCHEMA')");
  return 'App already running; no action taken.';
} catch (e) {
  // Not running -> start it
  run("CALL IDENTIFIER('MY_APP.PROCEDURES.START_APP')('MY_USER_SCHEMA')");
  return 'App start initiated.';
}
$$;

-- Idempotent STOP_APP
CREATE OR REPLACE PROCEDURE MY_DB.MY_SCHEMA.STOP_APP()
RETURNS STRING
LANGUAGE JAVASCRIPT
EXECUTE AS CALLER
AS
$$
function run(sql){ snowflake.execute({sqlText: sql}); }
try {
  // Try to stop; if already stopped, the call may error — swallow the error
  run("CALL IDENTIFIER('MY_APP.PROCEDURES.SHUTDOWN_APP')('MY_USER_SCHEMA')");
  return 'App stop initiated.';
} catch (e) {
  return 'App already stopped or stop not needed; no action taken.';
}
$$;
```

## **2. Use these in your Kumo BP SDK snippet**

If you have not set up the SDK yet, follow the [SDK setup guide](/fine-tuning/installation).

> **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):**

```sql
CALL MY_DB.MY_SCHEMA.START_APP();
```

**Python cell — Kumo BP SDK (make sure non\_blocking=False):**

```python
import kumoai

# Gather artifacts
pquery = kumoai.PredictiveQuery.load_from_training_job("trainingjob-...")
graph = pquery.graph

# Create a prediction table from the predictive query:
prediction_table = pquery.generate_prediction_table()

# Generate predictions:
trainer = kumoai.Trainer.load("trainingjob-...")
prediction_job = trainer.predict(
    graph,
    prediction_table,
    non_blocking = False  # <<< Make sure this is False so the notebook waits
)
```

**SQL cell — stop app (last line):**

```sql
CALL 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 expression and time zone, then 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`