Skip to content
Snippets Groups Projects
Commit 41f82f87 authored by ale's avatar ale
Browse files

remove duplicate configFile flag definition

parent 58be3c8d
Branches
No related tags found
No related merge requests found
......@@ -10,37 +10,26 @@ import (
"github.com/dgryski/dmrgo"
"git.autistici.org/ale/djrandom/api/task_api"
"git.autistici.org/ale/djrandom/services"
db_client "git.autistici.org/ale/djrandom/services/database/client"
"git.autistici.org/ale/djrandom/util/config"
"git.autistici.org/ale/djrandom/mapreduce"
)
var (
configFile = flag.String("config", "/etc/djrandom/server.conf", "Config file location")
cleanAllTasks = flag.Bool("all", false, "Clear all tasks (dangerous)")
maxJobAge = flag.Int64("max-age", 86400, "Task age cutoff")
)
type MRCleanTasks struct {
db services.Database
proto dmrgo.StreamProtocol
now int64
mapreduce.MapReduce
now int64
}
func (mr *MRCleanTasks) Map(key string, value string, emitter dmrgo.Emitter) {
jobId := value
// Create a database session.
session, err := mr.db.NewSession()
if err != nil {
return
}
defer session.Close()
// Fetch the job and delete it if it's too old.
if !*cleanAllTasks {
var job task_api.Job
if err := mr.db.Get(session, "tasks", jobId, &job); err != nil {
if err := mr.Db.Get(mr.Session, "tasks", jobId, &job); err != nil {
return
}
if !job.Final || (mr.now-job.CompletedAt) < *maxJobAge {
......@@ -48,7 +37,7 @@ func (mr *MRCleanTasks) Map(key string, value string, emitter dmrgo.Emitter) {
}
}
mr.db.Del(session, "tasks", jobId)
mr.Db.Del(mr.Session, "tasks", jobId)
log.Printf("removed job %s", jobId)
}
......@@ -59,14 +48,5 @@ func (mr *MRCleanTasks) Reduce(key string, values []string, emitter dmrgo.Emitte
}
func main() {
flag.Parse()
config.Parse(*configFile)
db := db_client.NewDatabaseImplFromConfig()
mr := &MRCleanTasks{
db: db,
proto: &dmrgo.JSONProtocol{},
now: time.Now().Unix(),
}
dmrgo.Main(mr)
mapreduce.Main(&MRCleanTasks{now: time.Now().Unix()}, nil)
}
......@@ -18,7 +18,6 @@ import (
)
var (
configFile = flag.String("config", "/etc/djrandom/server.conf", "Config file location")
memProfile = flag.String("memprofile", "", "save memory profile to file")
apply = flag.Bool("apply", false, "Really apply deduplication changes")
)
......
......@@ -13,9 +13,8 @@ import (
)
var (
configFile = flag.String("config", "/etc/djrandom/server.conf", "Config file location")
planName = flag.String("plan", "incoming", "Plan to execute")
state = flag.String("state", "", "Filter object with this state")
planName = flag.String("plan", "incoming", "Plan to execute")
state = flag.String("state", "", "Filter object with this state")
)
type MRReprocess struct {
......
......@@ -3,7 +3,6 @@
package main
import (
"flag"
"fmt"
"log"
"strings"
......@@ -16,10 +15,6 @@ import (
"git.autistici.org/ale/djrandom/util/instrumentation"
)
var (
configFile = flag.String("config", "/etc/djrandom/server.conf", "Config file location")
)
type MRStats struct {
mapreduce.MapReduce
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment