Skip to content

Commit

Permalink
Add command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
vassilux committed Sep 30, 2014
1 parent 1f50c9c commit 0f714e9
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ Import cdr asterisk datas from mysql backend to mongo
git clone git://github.com/alphazero/Go-Redis.git redis
cd redis
go install

****** Application startup

Application can be started with command line options

--config , the json configuration file

--tick , the value on seconds for schedule the import task



Expand Down
18 changes: 6 additions & 12 deletions config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dbMySqlHost": "192.168.3.20:3306",
"dbMySqlHost": "localhost:3306",
"dbMySqlUser": "root",
"dbMySqlPassword": "lepanos",
"dbMySqlName": "asteriskcdrdb",
Expand Down Expand Up @@ -42,16 +42,10 @@
{ "name": "simulate-outcall", "direction": 3},
{ "name": "test-teletech-alive-call", "direction": 1},
{ "name": "voicemenu-custom-2", "direction": 2},
{ "name": "voicemenu-custom-1", "direction": 2},
{ "name": "conferences", "direction": 2},
{ "name": "appc-esi-conference", "direction": 3},
{ "name": "app-recorde-prompt", "direction": 3},
{ "name": "appc-esi-conference-room-choise", "direction": 3}






{ "name": "voicemenu-custom-1", "direction": 2},
{ "name": "conferences", "direction": 2},
{ "name": "appc-esi-conference", "direction": 3},
{ "name": "app-recorde-prompt", "direction": 3},
{ "name": "appc-esi-conference-room-choise", "direction": 3}
]
}
1 change: 1 addition & 0 deletions logger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</exceptions>
<outputs formatid="all">
<file path="./log/all.log"/>
<console/>
<filter levels="info">
<console formatid="fmtinfo"/>
<file path="./log/infos.log"/>
Expand Down
30 changes: 17 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"errors"
"flag"
"fmt"
log "github.com/cihub/seelog"
"github.com/ziutek/mymysql/mysql"
Expand All @@ -15,7 +16,6 @@ import (
"sync"
"syscall"
"time"
//m "vorimport/models"
)

type Context struct {
Expand All @@ -38,6 +38,8 @@ var (
configLock = new(sync.RWMutex)
timeZoneOffset int64
isImportProcessing bool
configFile = flag.String("config", "config.json", "Configuration file path")
importTick = flag.Int("tick", 10, "Importing tick cycle")
)

const (
Expand Down Expand Up @@ -83,7 +85,7 @@ var (
*
*/
func loadConfig(fail bool) {
file, err := ioutil.ReadFile("config.json")
file, err := ioutil.ReadFile(*configFile)

if err != nil {
log.Errorf("Can't open configuration file : %s", err)
Expand Down Expand Up @@ -125,8 +127,8 @@ func GetConfig() *Config {

func init() {
//called on the start by go
loadConfig(true)
loadLogger()
//loadLogger()
//loadConfig(true)

s := make(chan os.Signal, 1)
signal.Notify(s, syscall.SIGUSR2)
Expand Down Expand Up @@ -181,16 +183,14 @@ func importJob() {
err := db.Connect()
if err != nil {
log.Criticalf("Can't connect to the mysql database error : %s.", err)
panic(err)
//os.Exit(1)
return
}
log.Debug("Connected to the mysql database with success.")
//
session, err := mgo.Dial(config.MongoHost)
if err != nil {
log.Debugf("Can't connect to the mongo database error : %s.", err)
//os.Exit(1)
panic(err)
return
}
session.SetMode(mgo.Monotonic, true)
defer session.Close()
Expand Down Expand Up @@ -308,10 +308,13 @@ func cleanup() {
}

func main() {
//
flag.Parse()

loadLogger()
loadConfig(true)

config = GetConfig()
//
//dummy flag for indicate that the import is processing
isImportProcessing = false
//
now := time.Now()
Expand All @@ -327,7 +330,8 @@ func main() {
os.Exit(1)
}()
//
ticker := time.NewTicker(3 * time.Second)
duration := time.Duration(*importTick) * time.Second
ticker := time.NewTicker(duration)
quit := make(chan struct{})
go func() {
for {
Expand All @@ -347,8 +351,8 @@ func main() {
}()

for {
log.Debug("Sleeping...")
time.Sleep(10 * time.Second) //
log.Debug("Working...")
time.Sleep(1000 * time.Second) //

}

Expand Down

0 comments on commit 0f714e9

Please sign in to comment.