Skip to content

pranavagiligar/the_switch

Repository files navigation

Scheduled Job Manager: Key Features

This application provides a single, cohesive solution for persistent job scheduling, execution, and management, designed for administrators needing reliable automation.

Core Architecture

Component Technology Role
Backend/Scheduler Go Handles API, authentication, data persistence, and CRON-based script execution.
Database SQLite Stores job definitions and user credentials persistently on disk (jobs.db).
Frontend HTML, Tailwind CSS, JS Single-page application (SPA) for real-time monitoring and management.

Feature Set

1. Robust Scheduling & Execution

  • Persistent CRON Scheduling: Jobs are stored in the database and re-loaded automatically when the server starts, ensuring schedules survive restarts.

  • 6-Field CRON Support: Utilizes a cron parser that supports second-level precision (Seconds, Minutes, Hours, Day of Month, Month, Day of Week).

  • Shell Script Execution ("The Bot"): Executes script content using /bin/bash -c, enabling the use of standard shell commands and local binaries (e.g., bash, python, node, etc.).

  • Execution Logging: All scheduled attempts, successful executions, and failures (including script output) are logged directly to the Go server's console for easy monitoring.

2. Job Management & Control

  • Full CRUD API: Administrators can Create, Read, Update, and Delete job definitions via the web interface.

  • Real-time Scheduler Reload: Any modification (create, update, delete) automatically triggers a graceful stop and reload of the internal CRON scheduler to apply changes instantly without requiring a full server restart.

  • Job Details: Each job card displays its name, description, script content, creation time, CRON expression, and critical status indicators.

3. Search & Sorting

The jobs list API (/api/jobs/) supports filtering and sorting via query parameters:

  • Search (?q=): Filter jobs by matching text in title or description

     GET /api/jobs/?q=backup   # Find jobs with "backup" in title/description
    
  • Sort (?sort=): Control the order of results

    • alphabetical - Sort by job title (A-Z)
    • date_created - Sort by creation date (newest first)
    • date_modified - Sort by last modification date (newest first)
    • next_schedule - Sort by next scheduled run time (soonest first)
     GET /api/jobs/?sort=next_schedule   # Show jobs ordered by next run time
    

Parameters can be combined:

GET /api/jobs/?q=backup&sort=date_modified

The web interface provides a search box and sort dropdown that use these parameters. Your chosen search and sort preferences persist across page reloads and are reflected in the URL (e.g. /?q=backup&sort=next_schedule).

4. The Skip Count Mechanism

The Skip Count feature provides temporary execution control without modifying the CRON schedule itself.

  • One-Click Skip: The Skip (Add 1) action increments the job's SkipCount.

  • Effective Next Run Calculation: The backend dynamically calculates the Next Run (Effective) time by advancing the schedule forward by the number of pending skips. This means the displayed time is the true next time the script will run.

  • Job Lifecycle Integration: When a scheduled time arrives, if SkipCount > 0, the job decrements the count and skips execution, maintaining the job's position in the CRON cycle.

4. Security and Usability

  • JWT Authentication: All API endpoints are protected by JWT tokens, requiring a successful username/password login.

  • Secure Password Storage: The server uses Bcrypt hashing for storing user passwords in the database.

  • User Interface: The interface is built with Tailwind CSS for a clean, responsive, and modern administrative experience.

Example script

#!/bin/bash
osascript -e 'display dialog "Your script ran successfully" with title "Hello from Bash" giving up after 2'

6 field cron generator

About

It is a Deadman's switch. It creates repeated task on a scheduler that can skip to next intervals

Topics

Resources

Stars

Watchers

Forks