Skip to content

Commit 8e59389

Browse files
Merge pull request #2 from raythurman2386/refactor/project-structure
refactor: reorganize project structure to follow Go best practices
2 parents 28c4f66 + 0f247ce commit 8e59389

File tree

13 files changed

+470
-502
lines changed

13 files changed

+470
-502
lines changed

GEMINI.md

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
## Key Files & Architecture
1616

17-
* **`cron.go`**: The core of the library. Contains:
18-
* `Cron`: The main scheduler engine managing the job list and run loop.
19-
* `Job`: Represents a scheduled task with its expression and state.
20-
* `Expression`: The parsed cron schedule using bitmasks.
21-
* `Parse()`: Logic to convert cron strings into `Expression` objects.
22-
* `run()`: The main event loop that waits for the next job or signal.
23-
* **`*_test.go`**: Unit tests ensuring correctness of parsing, scheduling, and concurrency.
17+
* **`cron.go`**: The core scheduler engine (`Cron` struct).
18+
* **`parser.go`**: Logic for parsing cron expressions and calculating next run times (`Expression`, `Parse`).
19+
* **`job.go`**: Job-related data structures (`Job`, `JobOptions`, `JobStatus`).
20+
* **`interfaces.go`**: Core interfaces (`JobStore`, `DistLock`) and policy definitions.
21+
* **`pkg/`**: Auxiliary packages and extensions:
22+
* `pkg/dashboard`: Web UI for monitoring.
23+
* `pkg/store/sqlite`: Persistence implementation.
24+
* `pkg/lock/redis`: Distributed locking implementation.
25+
* **`*_test.go`**: Comprehensive unit and integration tests.
2426

2527
## Building and Running
2628

@@ -43,10 +45,5 @@ go test ./... -v
4345
* **Language:** Go (1.24+)
4446
* **Concurrency:** Heavy reliance on Goroutines, Channels (`stopCh`, `addCh`), `sync.RWMutex` for state protection, and `sync.WaitGroup` for graceful shutdowns.
4547
* **Context:** Uses `context.Context` for job cancellation, especially relevant for the `OverlapReplace` policy.
46-
* **No External Dependencies:** The project relies solely on the Go standard library.
48+
* **No External Dependencies:** The core library relies solely on the Go standard library. External implementations (SQLite, Redis) are in `pkg/`.
4749
* **Formatting:** Standard `gofmt` style.
48-
49-
## Future Roadmap (from README)
50-
* Distributed locks (Redis/Etcd integration).
51-
* Persistence layer (SQLite/BadgerDB).
52-
* Web Dashboard for monitoring.

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ c.AddJobWithOptions("@every 1s", myTask, cronlib.JobOptions{
121121
Track job history and recover schedules across restarts.
122122

123123
```go
124-
import "github.com/raythurman2386/cronlib/store/sqlite"
124+
import "github.com/raythurman2386/cronlib/pkg/store/sqlite"
125125

126126
store, _ := sqlite.New("cron.db")
127127
c.SetJobStore(store)
@@ -131,7 +131,7 @@ c.SetJobStore(store)
131131
Ensure a job runs only once across a cluster.
132132

133133
```go
134-
import "github.com/raythurman2386/cronlib/lock/redis"
134+
import "github.com/raythurman2386/cronlib/pkg/lock/redis"
135135

136136
lock := redis.New("localhost:6379")
137137
c.SetDistLock(lock)
@@ -141,7 +141,7 @@ c.SetDistLock(lock)
141141
Embedded UI accessible at `http://localhost:8080`.
142142

143143
```go
144-
import "github.com/raythurman2386/cronlib/dashboard"
144+
import "github.com/raythurman2386/cronlib/pkg/dashboard"
145145

146146
http.Handle("/", dashboard.NewHandler(c))
147147
http.ListenAndServe(":8080", nil)

0 commit comments

Comments
 (0)