correct missing day from async reports
This commit is contained in:
parent
1e4abc63d0
commit
67054d524d
|
@ -5,15 +5,15 @@ module Jobs
|
|||
sidekiq_options retry: false
|
||||
|
||||
def execute(args)
|
||||
raise Discourse::InvalidParameters.new(:report_type) if !args["report_type"]
|
||||
raise Discourse::InvalidParameters.new(:report_type) if !args['report_type']
|
||||
|
||||
type = args.delete("report_type")
|
||||
type = args.delete('report_type')
|
||||
report = Report.new(type)
|
||||
report.start_date = args["start_date"].to_date if args["start_date"]
|
||||
report.end_date = args["end_date"].to_date if args["end_date"]
|
||||
report.category_id = args["category_id"] if args["category_id"]
|
||||
report.group_id = args["group_id"] if args["group_id"]
|
||||
report.facets = args["facets"].map(&:to_sym) if args["facets"]
|
||||
report.start_date = (args['start_date'].present? ? args['start_date'].to_date : 30.days.ago).beginning_of_day
|
||||
report.end_date = (args['end_date'].present? ? args['end_date'].to_date : start_date + 30.days).end_of_day
|
||||
report.category_id = args['category_id'] if args['category_id']
|
||||
report.group_id = args['group_id'] if args['group_id']
|
||||
report.facets = args['facets'].map(&:to_sym) if args['facets']
|
||||
|
||||
Report.send("report_#{type}", report)
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ class UserVisit < ActiveRecord::Base
|
|||
SELECT date_trunc('day', user_visits.visited_at)::DATE AS date,
|
||||
count(distinct user_visits.user_id) AS dau
|
||||
FROM user_visits
|
||||
WHERE user_visits.visited_at::DATE >= :start_date::DATE AND user_visits.visited_at < :end_date::DATE
|
||||
WHERE user_visits.visited_at::DATE >= :start_date::DATE AND user_visits.visited_at <= :end_date::DATE
|
||||
GROUP BY date_trunc('day', user_visits.visited_at)::DATE
|
||||
ORDER BY date_trunc('day', user_visits.visited_at)::DATE
|
||||
)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
require 'rails_helper'
|
||||
require_dependency 'jobs/base'
|
||||
|
||||
describe Jobs::RetrieveReport do
|
||||
it "correctly included full day in report" do
|
||||
freeze_time '2016-02-03 10:00'.to_date
|
||||
|
||||
_topic = Fabricate(:topic)
|
||||
|
||||
args = {
|
||||
report_type: :topics,
|
||||
start_date: Time.now.beginning_of_day,
|
||||
end_date: Time.now.end_of_day,
|
||||
facets: [:total]
|
||||
}.to_json
|
||||
|
||||
messages = MessageBus.track_publish("/admin/reports/topics") do
|
||||
Jobs::RetrieveReport.new.execute(JSON.parse(args))
|
||||
end
|
||||
|
||||
data = messages.first.data[:data]
|
||||
expect(data).to eq([y: 1, x: Time.now.to_date])
|
||||
end
|
||||
end
|
Loading…
Reference in New Issue