From d81063cc7986234a6b6276560fbd054a538d25cb Mon Sep 17 00:00:00 2001 From: Kevin Chabowski Date: Thu, 12 Sep 2013 23:40:28 +0200 Subject: Made jobsLimit and maxSchedules configurable --- jobedit.go | 28 ++++++++++++++++++++-------- mailremind.ini | 8 +++++++- main.go | 1 + 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/jobedit.go b/jobedit.go index f2f086f..ac9868d 100644 --- a/jobedit.go +++ b/jobedit.go @@ -53,11 +53,22 @@ func chronToSchedTL(chron chronos.Chronos, u model.User) scheduleTpldata { return schedule } -// TODO: Make these constants variable (config file or something...) -const ( - maxSchedules = 10 - jobsLimit = 100 -) +var maxSchedules, jobsLimit int + +func initLimits() { + schedules, err := conf.GetInt("limits", "schedules") + if err != nil { + log.Fatalf("Could not read config limits.schedules: %s", err) + } + + jobs, err := conf.GetInt("limits", "jobs") + if err != nil { + log.Fatalf("Could not read config limits.jobs: %s", err) + } + + maxSchedules = int(schedules) + jobsLimit = int(jobs) +} const bestTimeFmtEver = "2006-01-02 15:04:05" @@ -65,16 +76,17 @@ type jobeditTpldata struct { Error, Success string Fatal bool JobID, Subject, Content string - Schedules [maxSchedules]scheduleTpldata + Schedules []scheduleTpldata } func (jt *jobeditTpldata) fillFromJob(job model.Job, u model.User) { jt.JobID = job.ID().String() jt.Subject = job.Subject() jt.Content = string(job.Content()) + jt.Schedules = make([]scheduleTpldata, maxSchedules) for i, chron := range job.Chronos() { - if i == 10 { + if i == maxSchedules { log.Printf("Job %s has more than %d Chronos entries!", job.ID(), maxSchedules) break } @@ -193,7 +205,7 @@ func jobedit(user model.User, sess *sessions.Session, req *http.Request) (interf return &jobeditTpldata{Error: "You need to be logged in to do that.", Fatal: true}, user } - outdata := new(jobeditTpldata) + outdata := &jobeditTpldata{Schedules: make([]scheduleTpldata, maxSchedules)} // Try to load job, if given _id := mux.Vars(req)["ID"] diff --git a/mailremind.ini b/mailremind.ini index eb498d7..a4be249 100644 --- a/mailremind.ini +++ b/mailremind.ini @@ -28,4 +28,10 @@ arg2=kch42 [schedules] # How often should the schedules be checked? Unit is seconds. -checkInterval=30 \ No newline at end of file +checkInterval=30 + +[limits] +# How many schedules? MUST be > 0 +schedules=10 +# How many jobs per user? If < 0, unlimited. +jobs=100 \ No newline at end of file diff --git a/main.go b/main.go index 2dd98bf..02bcdbe 100644 --- a/main.go +++ b/main.go @@ -66,6 +66,7 @@ func main() { initMailing() initMails() initDB() + initLimits() defer dbcon.Close() staticpath, err := conf.GetString("paths", "static") -- cgit v1.2.3-54-g00ecf