mirror of
https://github.com/cgrates/cgrates.git
synced 2026-02-11 10:06:24 +05:00
updated vagrant and started smg simplification
This commit is contained in:
2
data/vagrant/Vagrantfile
vendored
2
data/vagrant/Vagrantfile
vendored
@@ -38,7 +38,7 @@ Vagrant.configure(2) do |config|
|
||||
# the path on the host to the actual folder. The second argument is
|
||||
# the path on the guest to mount the folder. And the optional third
|
||||
# argument is a set of non-required options.
|
||||
# config.vm.synced_folder "../data", "/vagrant_data"
|
||||
config.vm.synced_folder "../../", "/home/vagrant/code/src/github.com/cgrates/cgrates", owner: "vagrant", group: "vagrant"
|
||||
|
||||
# Provider-specific configuration so you can fine-tune various
|
||||
# backing providers for Vagrant. These expose provider-specific options.
|
||||
|
||||
@@ -24,8 +24,7 @@
|
||||
- name: install dependency
|
||||
apt: pkg={{ item }} update_cache=yes state=latest
|
||||
with_items:
|
||||
- git
|
||||
- bzr
|
||||
- git
|
||||
- mercurial
|
||||
- redis-server
|
||||
- mysql-server
|
||||
@@ -33,10 +32,11 @@
|
||||
- mongodb-org
|
||||
- freeswitch-meta-vanilla
|
||||
- freeswitch-mod-json-cdr
|
||||
- libyuv-dev
|
||||
- libyuv-dev
|
||||
- python-mysqldb
|
||||
|
||||
- name: update mysql root password for root account
|
||||
mysql_user: name=cgrates host=localhost password={{ root_db_password }}
|
||||
mysql_user: name=root host=localhost password={{ root_db_password }} state=present
|
||||
|
||||
- name: copy .my.cnf
|
||||
template: src=my.cnf dest=/root/.my.cnf mode=0600
|
||||
@@ -47,35 +47,25 @@
|
||||
go_version: 1.6
|
||||
|
||||
tasks:
|
||||
- name: create cgrates path
|
||||
file: path=/home/vagrant/code/src/github.com/cgrates state=directory
|
||||
|
||||
- name: get golang
|
||||
unarchive: src=https://storage.googleapis.com/golang/go{{ go_version }}.linux-amd64.tar.gz dest=~/go creates=~/go copy=no
|
||||
unarchive: src=https://storage.googleapis.com/golang/go{{ go_version }}.linux-amd64.tar.gz dest=~/ creates=~/go copy=no
|
||||
|
||||
- name: add variables to variables /etc/profile
|
||||
copy: src=golang.sh dest=/etc/profile.d/golang.sh
|
||||
become: yes
|
||||
|
||||
- name: get cgrates
|
||||
git: repo=https://github.com/cgrates/cgrates.git dest=/home/vagrant/code/src/github.com/cgrates/cgrates
|
||||
|
||||
- name: get glide
|
||||
shell: GOROOT=/home/vagrant/go GOPATH=/home/vagrant/code ~/go/bin/go get -u -v github.com/Masterminds/glide
|
||||
|
||||
- name: install cgrates
|
||||
shell: cd /home/vagrant/code/src/github.com/cgrates/cgrates; ~/code/bin/glide install
|
||||
|
||||
- name: create cgr-engine link
|
||||
file: src=/home/vagrant/code/bin/cgr-engine dest=/usr/bin/cgr-engine state=link
|
||||
become: yes
|
||||
|
||||
- name: create a link to data dir
|
||||
become: yes
|
||||
- name: create a link to data dir
|
||||
file: src=/home/vagrant/code/src/github.com/cgrates/cgrates/data dest=/usr/share/cgrates state=link
|
||||
become: yes
|
||||
|
||||
- name: expand freeswitch json conf
|
||||
command: tar -xzvf /usr/share/cgrates/tutorials/fs_json/freeswitch/etc/freeswitch_conf.tar.gz
|
||||
#- name: expand freeswitch json conf
|
||||
# unarchive: src=/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/freeswitch_conf.tar.gz dest=/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/ copy=no
|
||||
|
||||
- name: expand freeswitch csv conf
|
||||
command: tar -xzvf /usr/share/cgrates/tutorials/fs_csv/freeswitch/etc/freeswitch_conf.tar.gz
|
||||
#- name: expand freeswitch csv conf
|
||||
# unarchive: src=/usr/share/cgrates/tutorials/fs_csv/freeswitch/etc/freeswitch_conf.tar.gz dest=/usr/share/cgrates/tutorials/fs_json/freeswitch/etc/ copy=no
|
||||
|
||||
- name: setup database tables
|
||||
shell: chdir=/usr/share/cgrates/storage/mysql ./setup_cgr_db.sh root {{ root_db_password }} localhost
|
||||
|
||||
@@ -41,7 +41,7 @@ type SMGSession struct {
|
||||
sessionCds []*engine.CallDescriptor
|
||||
callCosts []*engine.CallCost
|
||||
extraDuration time.Duration // keeps the current duration debited on top of what heas been asked
|
||||
lastUsage time.Duration // Keep record of the last debit for LastUsed functionality
|
||||
lastUsage time.Duration
|
||||
totalUsage time.Duration
|
||||
}
|
||||
|
||||
@@ -78,21 +78,20 @@ func (self *SMGSession) debitLoop(debitInterval time.Duration) {
|
||||
|
||||
// Attempts to debit a duration, returns maximum duration which can be debitted or error
|
||||
func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.Duration, error) {
|
||||
lastUsedCorrection := time.Duration(0) // Used if lastUsed influences the debit
|
||||
if self.cd.DurationIndex != 0 && lastUsed != 0 {
|
||||
if self.lastUsage > lastUsed { // We have debitted more than we have used, refund in the duration debitted
|
||||
lastUsedCorrection = -(self.lastUsage - lastUsed)
|
||||
} else { // We have debitted less than we have consumed, add the difference to duration debitted
|
||||
lastUsedCorrection = lastUsed - self.lastUsage
|
||||
}
|
||||
self.totalUsage += lastUsed // Should reflect the total usage so far
|
||||
|
||||
// apply the lastUsed correction
|
||||
dur += lastUsedCorrection
|
||||
self.totalUsage += lastUsed // Should reflect the total usage so far
|
||||
} else {
|
||||
// apply correction from previous run
|
||||
dur -= self.extraDuration
|
||||
if lastUsed > 0 {
|
||||
self.extraDuration = self.lastUsage - lastUsed
|
||||
}
|
||||
// apply correction from previous run
|
||||
if self.extraDuration < dur {
|
||||
dur -= self.extraDuration
|
||||
} else {
|
||||
ccDuration := self.extraDuration // fake ccDuration
|
||||
self.extraDuration -= dur
|
||||
return ccDuration, nil
|
||||
}
|
||||
|
||||
self.extraDuration = 0
|
||||
if self.cd.LoopIndex > 0 {
|
||||
self.cd.TimeStart = self.cd.TimeEnd
|
||||
@@ -117,11 +116,7 @@ func (self *SMGSession) debit(dur time.Duration, lastUsed time.Duration) (time.D
|
||||
self.cd.LoopIndex += 1
|
||||
self.sessionCds = append(self.sessionCds, self.cd.Clone())
|
||||
self.callCosts = append(self.callCosts, cc)
|
||||
ccDuration -= lastUsedCorrection
|
||||
if ccDuration < 0 { // if correction has pushed ccDuration bellow 0
|
||||
ccDuration = 0
|
||||
}
|
||||
self.lastUsage = ccDuration // Reset the lastUsage for later reference
|
||||
self.lastUsage = ccDuration
|
||||
return ccDuration, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user