summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin Chabowski <kevin@kch42.de>2013-09-12 23:40:28 +0200
committerKevin Chabowski <kevin@kch42.de>2013-09-12 23:40:28 +0200
commitd81063cc7986234a6b6276560fbd054a538d25cb (patch)
tree038cceb7fccf718f7ee6b03d4dd645a389ee11b4
parentabe7117874e6215cde2e63b97971ac629769190a (diff)
downloadmailremind-d81063cc7986234a6b6276560fbd054a538d25cb.tar.gz
mailremind-d81063cc7986234a6b6276560fbd054a538d25cb.tar.bz2
mailremind-d81063cc7986234a6b6276560fbd054a538d25cb.zip
Made jobsLimit and maxSchedules configurable
-rw-r--r--jobedit.go28
-rw-r--r--mailremind.ini8
-rw-r--r--main.go1
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")