smartkiosk-client 0.1.2 → 0.1.3
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/terminal.rb +4 -0
- data/app/models/session_record.rb +3 -0
- data/app/models/terminal.rb +5 -0
- data/app/workers/ping_worker.rb +41 -3
- data/bin/smartkiosk-client +13 -2
- data/db/migrate/20130216114539_create_session_records.rb +12 -0
- data/lib/smartkiosk/client/version.rb +1 -1
- data/smartkiosk-client.gemspec +1 -1
- metadata +8 -6
data/app/controllers/terminal.rb
CHANGED
data/app/models/terminal.rb
CHANGED
data/app/workers/ping_worker.rb
CHANGED
@@ -5,6 +5,7 @@ class PingWorker
|
|
5
5
|
|
6
6
|
sidekiq_options :retry => false, :queue => :pings
|
7
7
|
|
8
|
+
DAY = 24 * 3600
|
8
9
|
SEMAPHORE = ConnectionPool.new(:size => 1, :timeout => 5) { true }
|
9
10
|
|
10
11
|
def perform
|
@@ -14,16 +15,49 @@ class PingWorker
|
|
14
15
|
|
15
16
|
Sidekiq::Logging.logger.info "Requesting with updated_at: #{Terminal.providers_updated_at}"
|
16
17
|
|
18
|
+
sessions_per_day = {}
|
19
|
+
sessions = SessionRecord.all
|
20
|
+
|
21
|
+
sessions.each do |session|
|
22
|
+
next if session.time == 0
|
23
|
+
|
24
|
+
session_start = session.started_at
|
25
|
+
session_start -= session_start % DAY
|
26
|
+
session_end = session.started_at + session.time
|
27
|
+
|
28
|
+
session_start.step(session_end - 1, DAY) do |day|
|
29
|
+
day_time = [ day + DAY - 1, session.started_at + session.time ].min -
|
30
|
+
[ day, session.started_at ].max
|
31
|
+
|
32
|
+
fraction = day_time / session.time
|
33
|
+
|
34
|
+
sessions_per_day[day] = {
|
35
|
+
upstream: session.upstream * fraction,
|
36
|
+
downstream: session.downstream * fraction,
|
37
|
+
time: session.time * fraction
|
38
|
+
}
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
sessions.each do |day, charges|
|
43
|
+
Sidekiq::Logging.logger.info "reporting #{charges.inspect} on #{day}"
|
44
|
+
end
|
45
|
+
|
17
46
|
begin
|
18
47
|
response = RestClient::Request.execute(
|
19
48
|
:method => :post,
|
20
49
|
:url => "#{Terminal.config.host}/terminal_pings",
|
21
50
|
:timeout => 40,
|
22
51
|
:open_timeout => 60,
|
23
|
-
:
|
52
|
+
:headers => {
|
53
|
+
"Content-Type" => "application/json",
|
54
|
+
"Accept" => "application/json"
|
55
|
+
},
|
56
|
+
:payload => JSON.dump(
|
24
57
|
:terminal => Terminal.keyword,
|
25
|
-
:terminal_ping => condition
|
26
|
-
|
58
|
+
:terminal_ping => condition,
|
59
|
+
:sessions => sessions_per_day
|
60
|
+
)
|
27
61
|
)
|
28
62
|
rescue Exception => e
|
29
63
|
Sidekiq::Logging.logger.warn e.to_s
|
@@ -39,6 +73,10 @@ class PingWorker
|
|
39
73
|
|
40
74
|
Sidekiq::Logging.logger.info "Response: #{response.inspect}"
|
41
75
|
|
76
|
+
ActiveRecord::Base.transaction do
|
77
|
+
sessions.each &:destroy
|
78
|
+
end
|
79
|
+
|
42
80
|
#
|
43
81
|
# PROFILE
|
44
82
|
#
|
data/bin/smartkiosk-client
CHANGED
@@ -42,8 +42,19 @@ EventMachine.run do
|
|
42
42
|
@front_orders.push ['modified_at', Terminal.modified_at].to_json
|
43
43
|
end
|
44
44
|
|
45
|
-
Smartware.subscribe do |
|
46
|
-
|
45
|
+
Smartware.subscribe do |message|
|
46
|
+
if message.key == "modem.accounting"
|
47
|
+
message.acknowlege
|
48
|
+
|
49
|
+
p message
|
50
|
+
|
51
|
+
SessionRecord.create(started_at: message[0],
|
52
|
+
upstream: message[1],
|
53
|
+
downstream: message[2],
|
54
|
+
time: message[3])
|
55
|
+
else
|
56
|
+
@front_orders.push ["smartware.#{message.key}", message.args].to_json
|
57
|
+
end
|
47
58
|
end
|
48
59
|
|
49
60
|
EventMachine::WebSocket.run(:host => '0.0.0.0', :port => 3002) do |ws|
|
data/smartkiosk-client.gemspec
CHANGED
@@ -49,7 +49,7 @@ Gem::Specification.new do |gem|
|
|
49
49
|
gem.add_dependency 'rubyzip', '0.9.9'
|
50
50
|
gem.add_dependency 'pry', '0.9.10'
|
51
51
|
|
52
|
-
gem.add_dependency 'smartware', '0.4.
|
52
|
+
gem.add_dependency 'smartware', '0.4.9'
|
53
53
|
gem.add_dependency 'smartguard', '0.4.3'
|
54
54
|
|
55
55
|
gem.add_dependency 'sidekiq', '2.6.5'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: smartkiosk-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-16 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -435,7 +435,7 @@ dependencies:
|
|
435
435
|
requirements:
|
436
436
|
- - '='
|
437
437
|
- !ruby/object:Gem::Version
|
438
|
-
version: 0.4.
|
438
|
+
version: 0.4.9
|
439
439
|
type: :runtime
|
440
440
|
prerelease: false
|
441
441
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -443,7 +443,7 @@ dependencies:
|
|
443
443
|
requirements:
|
444
444
|
- - '='
|
445
445
|
- !ruby/object:Gem::Version
|
446
|
-
version: 0.4.
|
446
|
+
version: 0.4.9
|
447
447
|
- !ruby/object:Gem::Dependency
|
448
448
|
name: smartguard
|
449
449
|
requirement: !ruby/object:Gem::Requirement
|
@@ -538,6 +538,7 @@ files:
|
|
538
538
|
- app/models/provider.rb
|
539
539
|
- app/models/receipt.rb
|
540
540
|
- app/models/receipt_template.rb
|
541
|
+
- app/models/session_record.rb
|
541
542
|
- app/models/terminal.rb
|
542
543
|
- app/uploaders/icon_uploader.rb
|
543
544
|
- app/views/banners.haml
|
@@ -577,6 +578,7 @@ files:
|
|
577
578
|
- db/migrate/20130106181844_create_phone_ranges.rb
|
578
579
|
- db/migrate/20130108110546_create_promotions.rb
|
579
580
|
- db/migrate/20130110025256_create_banners.rb
|
581
|
+
- db/migrate/20130216114539_create_session_records.rb
|
580
582
|
- init.rb
|
581
583
|
- lib/patches/sidekiq.rb
|
582
584
|
- lib/pinger.rb
|
@@ -608,7 +610,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
608
610
|
version: '0'
|
609
611
|
segments:
|
610
612
|
- 0
|
611
|
-
hash:
|
613
|
+
hash: 2149702848177027716
|
612
614
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
613
615
|
none: false
|
614
616
|
requirements:
|
@@ -617,7 +619,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
617
619
|
version: '0'
|
618
620
|
segments:
|
619
621
|
- 0
|
620
|
-
hash:
|
622
|
+
hash: 2149702848177027716
|
621
623
|
requirements: []
|
622
624
|
rubyforge_project:
|
623
625
|
rubygems_version: 1.8.24
|