~singpolyma/sgx-jmp

b6ad9e219973b8983d5cb290544a9f6786f440b6 — Stephen Paul Weber 1 year, 25 days ago 51121d1 + bc13638
Merge branch 'count-outbound-messages'

* count-outbound-messages:
  Store customer outbound messages/day for 1 year in redis
2 files changed, 19 insertions(+), 1 deletions(-)

M .rubocop.yml
M sgx_jmp.rb
M .rubocop.yml => .rubocop.yml +3 -0
@@ 71,3 71,6 @@ Layout/IndentArray:

Style/FormatString:
  EnforcedStyle: percent

Style/FormatStringToken:
  EnforcedStyle: unannotated

M sgx_jmp.rb => sgx_jmp.rb +16 -1
@@ 5,6 5,7 @@ require "bigdecimal"
require "blather/client/dsl" # Require this first to not auto-include
require "blather/client"
require "braintree"
require "date"
require "dhall"
require "em-hiredis"
require "em_promise"


@@ 127,7 128,21 @@ end

message do |m|
	Customer.for_jid(m.from.stripped).then { |customer|
		customer.stanza_from(m)
		today = Time.now.utc.to_date
		EMPromise.all([
			REDIS.zremrangebylex(
				"jmp_customer_outbound_messages-#{customer.customer_id}",
				"-",
				# Store message counts per day for 1 year
				"[#{(today << 12).strftime('%Y%m%d')}"
			),
			REDIS.zincrby(
				"jmp_customer_outbound_messages-#{customer.customer_id}",
				1,
				today.strftime("%Y%m%d")
			),
			customer.stanza_from(m)
		])
	}.catch(&method(:panic))
end