Scheduled Jobs & Hooks

Overview

This document explains the background job processing, scheduled tasks, and application configuration used in the Lnder Logistics module. The module manages vehicle tracking, geofence alerts, trip metrics processing, and system maintenance tasks.


1. Background Job Processing

The system uses Frappe Background Jobs to execute long-running operations asynchronously without blocking user requests.

Key Benefits

  • Improves system performance
  • Handles heavy computations asynchronously
  • Prevents duplicate job execution
  • Ensures reliable data processing

2. Geofence Alert Processing

Function

trigger_create_geofence_alert_log()

This function schedules a background job that validates whether vehicles have entered or exited configured geofence locations.

Workflow

  1. Check if geofence validation job already exists
  2. If not running, enqueue the job
  3. Execute geofence tracking validation
  4. Create Geofence Vehicle Alert Logs

3. Active Tracking Processing

Function

process_all_active_tracking()

This function processes all logistics tracking records created in the last two days. Each tracking record is processed in a separate background job.

Purpose

  • Update tracking status
  • Process vehicle coordinates
  • Update tracking logs
  • Maintain real-time vehicle tracking

4. Tracking URL Expiry Management

Function

update_all_url_expiry_time()

Tracking URLs are temporary public links used for vehicle tracking. This job updates expiry times and disables expired links automatically.

Workflow

  1. Fetch all active tracking URLs
  2. Calculate expiry time based on configuration
  3. Update expiry time in database
  4. Disable expired URLs

Configuration Source

The expiry duration is configured in Logistics Settings → Extended Tracking Link Expiry.


5. Fleet Tracker Cache Update

Function

trigger_cache_fleet_tracker_page_functions()

This job refreshes cached vehicle data used in the Fleet Tracker dashboard.

Purpose

  • Improve page load performance
  • Cache vehicle status information
  • Prepare dashboard data in advance

6. Automatic Log Cleanup

Functions

  • clear_old_logs()
  • clear_old_alert_logs()

These jobs automatically remove old logs to prevent database growth.

Log Types Cleaned

Log Type Purpose
Logistics Tracking API Log Stores API request/response history
Logistics Tracking Alert Log Stores vehicle alert history

Retention Configuration

Retention periods are configured in Logistics Settings.


7. Trip Metrics Calculation

Function

update_all_trip_metrics_for_tracking()

This job calculates trip metrics for logistics tracking records where trip information is incomplete.

Metrics Calculated

  • Trip Start Odometer
  • Trip End Odometer
  • Trip Distance
  • Fuel Consumption
  • Vehicle Mileage

Processing Scope

Only tracking records from the last 2 days are processed.


8. Bulk Tracking Updates

API Method

bulk_update_tracking_bg()

This whitelisted API method allows bulk background updates of multiple tracking records.

Features

  • Accepts list of tracking IDs
  • Creates background jobs for each tracking
  • Prevents duplicate job execution

9. Bulk Trip Metrics Update

API Method

bulk_update_trip_metrics_bg()

Triggers trip metric recalculation for multiple tracking records.


10. Scheduler Configuration

The system uses Frappe Scheduler Events to automate background processing.

Cron Schedule

Interval Job Purpose
Every 5 minutes Geofence Validation Detect vehicle geofence entry/exit
Every 10 minutes Cache Fleet Tracker Refresh dashboard vehicle data
Every 10 minutes Update Tracking URL Expiry Disable expired tracking links
Every 15 minutes Process Active Tracking Update vehicle tracking data
Every 14 minutes Trip Metrics Processing Update trip distance and fuel metrics

Daily Jobs

Job Purpose
Clear Old Logs Delete expired API logs
Clear Old Alert Logs Delete expired alert logs

11. Application Configuration

App Metadata

Property Value
App Name lnder_logistics
App Title Lnder Logistics
Publisher Aerele
Description Logistics and Fleet Management for Vehicle Operations
License MIT

12. UI and Frontend Integration

Leaflet Map Integration

The application integrates the Leaflet.js mapping library for vehicle tracking and geofence visualization.

Included Libraries

  • Leaflet Map Library
  • Leaflet Draw Plugin

Usage

  • Display vehicle location on maps
  • Create and edit geofence areas
  • Track vehicles visually

13. Custom Route Configuration

The application exposes a public vehicle tracking page using a custom route.

Route

/track/<tracking_id>

Purpose

  • Allow customers to track vehicles
  • Provide real-time tracking information
  • Share tracking links externally

14. Document Event Hooks

Custom validations are executed when specific DocTypes are validated.

DocType Event Purpose
Address Validate Custom address validation
Vehicle Validate Vehicle configuration validation
User Validate User validation rules

Summary

The Lnder Logistics module relies heavily on scheduled background jobs to manage vehicle tracking, geofence alerts, trip metrics, and system maintenance. This architecture ensures high performance, scalability, and reliable logistics monitoring.

Discard
Save
This page has been updated since your last edit. Your draft may contain outdated content. Load Latest Version

On this page

Review Changes ← Back to Content
Message Status Space Raised By Last update on