Skip to main content

Functions

Create and manage serverless functions to build your application's backend logic.

Overview

Functions are serverless code units that execute in response to HTTP requests, scheduled triggers, or events. Write Python code that runs on Taruvi's infrastructure without managing servers.


Concepts

Function

A serverless code unit that executes Python code in response to triggers. Functions can be synchronous (immediate response), asynchronous (background processing), or scheduled (cron-based).

Execution Mode

Determines how and when a function runs:

  • Synchronous: Executes and returns a response immediately
  • Asynchronous: Executes in the background, returns a task ID
  • Scheduled: Executes automatically on a cron schedule

Function Slug

A URL-friendly identifier for your function, used in API endpoints and internal references.


View Functions

  1. Navigate to your App in the Dashboard.
  2. Click the Functions section in the sidebar.
  3. View all functions with:
    • Name: Function display name
    • Execution Mode: Sync, Async, or Scheduled
    • Status: Active or Inactive
    • Last Updated: Most recent modification

Filter Functions

Use the filter options to narrow the list:

  • Execution Mode: Show only sync, async, or scheduled functions
  • Status: Show only active or inactive functions
  • Search: Find functions by name

Create a Function

  1. Navigate to your App in the Dashboard.
  2. Click Functions in the sidebar.
  3. Click Create Function.
  4. Fill in the function details:
    • Name: Descriptive function name
    • Slug: URL identifier (auto-generated from name)
    • Description: Purpose of the function
    • Execution Mode: Select Sync, Async, or Scheduled
    • Status: Active or Inactive
  5. Click Create.

Function Detail Page

Click on a function to access its detail page with multiple tabs:

Code Tab

Edit your function's Python code:

  1. Click the Code tab.
  2. Use the Monaco editor to write Python code.
  3. Click Save to update the function.
def handler(request, context):
# Your function logic here
return {
"status": 200,
"body": {"message": "Hello, World!"}
}
tip

Use the request parameter to access HTTP request data and the context parameter for runtime context like secrets and environment variables.

Config Tab

Configure function settings:

  1. Click the Config tab.
  2. Configure:
    • Metadata: Name, description, execution mode
    • Headers: Custom HTTP response headers
    • Authentication: Require auth for function calls
    • Scheduling: Cron schedules (for scheduled functions)
    • Celery Config: Background task settings (for async functions)
  3. Click Save Changes.

Docs Tab

View and edit function documentation:

  1. Click the Docs tab.
  2. View auto-generated API documentation.
  3. Edit the markdown description.
  4. View input/output schemas.

Execute Tab

Test your function directly:

  1. Click the Execute tab.
  2. Enter request parameters (JSON format).
  3. Click Execute.
  4. View the response:
    • Status: HTTP status code
    • Response Body: JSON response
    • Execution Time: How long it took

Version History Tab

Track code changes:

  1. Click the Version History tab.
  2. View all saved versions with timestamps.
  3. Click a version to see the code diff.
  4. Revert to a previous version if needed.

Execution History Tab (Runs)

Monitor function executions:

  1. Click the Runs tab.
  2. View recent executions:
    • Timestamp: When it ran
    • Status: Success or Failed
    • Duration: Execution time
    • Triggered By: How it was invoked
  3. Click a run to view details and logs.

Edit a Function

  1. Navigate to the function detail page.
  2. Click the Edit (pencil) icon.
  3. Update function settings in the dialog.
  4. Click Save Changes.

Delete a Function

  1. Navigate to the function detail page.
  2. Click the Delete (trash) icon.
  3. Confirm deletion in the dialog.
warning

Deleting a function removes all code, configuration, and execution history. This action cannot be undone.


Execution Modes

Synchronous Functions

  • Execute immediately when called
  • Return response directly to caller
  • Best for: API endpoints, quick operations

Asynchronous Functions

  • Execute in background queue
  • Return task ID immediately
  • Poll for completion status
  • Best for: Long-running tasks, batch processing

Scheduled Functions

  • Execute automatically on schedule
  • Use cron expressions for timing
  • Best for: Periodic jobs, cleanup tasks

Cron Schedule Format

┌───────────── minute (0 - 59)
│ ┌───────────── hour (0 - 23)
│ │ ┌───────────── day of month (1 - 31)
│ │ │ ┌───────────── month (1 - 12)
│ │ │ │ ┌───────────── day of week (0 - 6)
│ │ │ │ │
* * * * *

Examples:

  • 0 * * * * - Every hour
  • 0 0 * * * - Daily at midnight
  • 0 0 * * 0 - Weekly on Sunday
  • */15 * * * * - Every 15 minutes

Configuration

Function Fields

FieldDescriptionRequired
NameDisplay nameYes
SlugURL identifierAuto-generated
DescriptionPurpose of functionNo
Execution ModeSync, Async, ScheduledYes
Is ActiveEnable/disable functionYes

Header Configuration

Add custom HTTP headers to responses:

SettingDescription
Header NameHTTP header key
Header ValueHTTP header value

Authentication

SettingDescription
Require AuthRequire authentication to call
Auth TypeToken, API Key, or JWT

Limits

ResourceLimit
Functions per app100
Code size10 MB
Execution timeout30 seconds (sync)
Background timeout5 minutes (async)
Memory256 MB
info

Need higher limits? Contact support to discuss your requirements.


Troubleshooting

Function returns error

Problem: Function execution fails with an error.

Solution:

  1. Check the Runs tab for error details.
  2. Review the error message and stack trace.
  3. Test locally with the same input.
  4. Check for syntax errors in your code.

Scheduled function not running

Problem: A scheduled function isn't executing on schedule.

Solution:

  1. Verify the function is Active.
  2. Check the cron expression is valid.
  3. Review execution history for errors.
  4. Ensure the schedule is enabled in Config.

Timeout errors

Problem: Function times out before completing.

Solution:

  1. Optimize code for faster execution.
  2. Use async mode for long-running tasks.
  3. Break large operations into smaller functions.
  4. Consider increasing timeout limits (if available).

Last Updated: January 2025