How atifh/clj-scheduler works
Project Type and Purpose
• Type: Back‐end scheduling service (demo) with a lightweight web view
• Purpose: Integrate Quartz Scheduler in Clojure to run one-time, periodic, persistent, and cron tasks, backed by Postgres, with a Ring‐based UI for listing jobs.
File Structure
• Top-level directories:
– config/ : profile-specific config EDN files
– resources/ : Quartz properties, Logback config, SQL schema
– src/clj_scheduler/ : Clojure namespaces (core, db, log, various task modules)
– templates/ : HTML template for web view
– test/ : unit tests
• Key files:
– project.clj : dependencies (Quartz, JDBC, Ring, Hiccup/Selmer)
– setup_db.sh + quartz_tables_postgres.sql: Postgres job store setup
– resources/quartz.properties: Quartz engine config
– resources/logback.xml: logging config
README for Additional Insights
• Dependencies: Postgres, Leiningen, Clojure
• Usage flows:
– Running one-time, periodic, persistent, cron jobs via REPL API
– Running Ring server to serve an HTML page listing scheduled jobs
Main Components
a. Configuration Layer
• EDN files (dev/test/prod) and quartz.properties
• Injects DB connection info, scheduler properties, logging path
b. Scheduler Engine
• Quartz Scheduler embedded inside the Clojure app
• Uses a JDBC JobStore (Postgres) for persistence
c. Database
• Postgres instance with Quartz tables
• Populated via setup_db.sh + SQL script
d. Task Modules
• Namespaces: one_time_tasks, periodic_tasks, persistent_tasks, persistent_cron_tasks
• Each exposes a (schedule-job) function to register jobs with Quartz
e. Core & DB Access
• core.clj: initializes the scheduler, handles lifecycle
• db.clj: wraps JDBC calls (reads/writes Quartz meta-tables if needed)
f. Logging
• log.clj + logback.xml: routes scheduler and application logs to file
g. Web UI
• Ring server (in core.clj via “lein run server”)
• templates/tasks.html rendered via Hiccup or Selmer
• HTTP endpoint: GET / --> lists jobs by querying the Quartz store
Relationships & Data Flow
– App startup reads config → initializes Quartz with quartz.properties & DB credentials
– Task module calls → scheduler.scheduleJob() → Quartz enqueues job into JobStore
– Quartz thread pool executes jobs → task logic runs → logs emitted to file
– Web request → Ring handler → queries JobStore via core/db → renders tasks.html → HTTP response
Architectural Patterns & Tech
– Layered design: Config → Infrastructure (Quartz, DB, Logging) → Application logic (task modules, core) → Presentation (Ring + templates)
– Externalized configuration (EDN + properties)
– JDBC JobStore pattern for persistence
– REPL‐driven execution of task registration
Putting It All Together
1. Config Layer
2. Scheduler Engine
3. Task Modules
4. Core/DB Access
5. Web UI
6. Logging
– Connect Config → Scheduler Engine
– Connect Scheduler Engine ↔ Postgres DB
– Connect Scheduler Engine → Task Modules
– Connect Task Modules → Logging subsystem
– Connect Client Browser → Web UI → Core/DB Access → Postgres DB
– At the edge, show external tools: Leiningen, Postgres CLI, setup_db.sh