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
- Navigate to your App in the Dashboard.
- Click the Functions section in the sidebar.
- 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
- Navigate to your App in the Dashboard.
- Click Functions in the sidebar.
- Click Create Function.
- 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
- 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:
- Click the Code tab.
- Use the Monaco editor to write Python code.
- Click Save to update the function.
def handler(request, context):
# Your function logic here
return {
"status": 200,
"body": {"message": "Hello, World!"}
}
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:
- Click the Config tab.
- 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)
- Click Save Changes.
Docs Tab
View and edit function documentation:
- Click the Docs tab.
- View auto-generated API documentation.
- Edit the markdown description.
- View input/output schemas.
Execute Tab
Test your function directly:
- Click the Execute tab.
- Enter request parameters (JSON format).
- Click Execute.
- View the response:
- Status: HTTP status code
- Response Body: JSON response
- Execution Time: How long it took
Version History Tab
Track code changes:
- Click the Version History tab.
- View all saved versions with timestamps.
- Click a version to see the code diff.
- Revert to a previous version if needed.
Execution History Tab (Runs)
Monitor function executions:
- Click the Runs tab.
- View recent executions:
- Timestamp: When it ran
- Status: Success or Failed
- Duration: Execution time
- Triggered By: How it was invoked
- Click a run to view details and logs.
Edit a Function
- Navigate to the function detail page.
- Click the Edit (pencil) icon.
- Update function settings in the dialog.
- Click Save Changes.
Delete a Function
- Navigate to the function detail page.
- Click the Delete (trash) icon.
- Confirm deletion in the dialog.
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 hour0 0 * * *- Daily at midnight0 0 * * 0- Weekly on Sunday*/15 * * * *- Every 15 minutes
Configuration
Function Fields
| Field | Description | Required |
|---|---|---|
| Name | Display name | Yes |
| Slug | URL identifier | Auto-generated |
| Description | Purpose of function | No |
| Execution Mode | Sync, Async, Scheduled | Yes |
| Is Active | Enable/disable function | Yes |
Header Configuration
Add custom HTTP headers to responses:
| Setting | Description |
|---|---|
| Header Name | HTTP header key |
| Header Value | HTTP header value |
Authentication
| Setting | Description |
|---|---|
| Require Auth | Require authentication to call |
| Auth Type | Token, API Key, or JWT |
Limits
| Resource | Limit |
|---|---|
| Functions per app | 100 |
| Code size | 10 MB |
| Execution timeout | 30 seconds (sync) |
| Background timeout | 5 minutes (async) |
| Memory | 256 MB |
Need higher limits? Contact support to discuss your requirements.
Troubleshooting
Function returns error
Problem: Function execution fails with an error.
Solution:
- Check the Runs tab for error details.
- Review the error message and stack trace.
- Test locally with the same input.
- Check for syntax errors in your code.
Scheduled function not running
Problem: A scheduled function isn't executing on schedule.
Solution:
- Verify the function is Active.
- Check the cron expression is valid.
- Review execution history for errors.
- Ensure the schedule is enabled in Config.
Timeout errors
Problem: Function times out before completing.
Solution:
- Optimize code for faster execution.
- Use async mode for long-running tasks.
- Break large operations into smaller functions.
- Consider increasing timeout limits (if available).
Related
Last Updated: January 2025