Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Subscription support shows data collection time, and completion… #37

Merged
merged 3 commits into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/graphql/types/subscription/subscription_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ class SubscriptionType < Types::BaseObject
field :level, String, null: false
field :status, String, null: false
field :count, Integer, null: false
field :status_updated_at, GraphQL::Types::ISO8601DateTime, null: false
field :status_updated_at, GraphQL::Types::ISO8601DateTime, null: true
field :collect_at, GraphQL::Types::ISO8601DateTime, null: true
field :complete_at, GraphQL::Types::ISO8601DateTime, null: true
end
end
end
2 changes: 2 additions & 0 deletions app/models/subject.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# status_updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# collect_at :datetime
# complete_at :datetime
#
# Indexes
#
Expand Down
2 changes: 1 addition & 1 deletion app/models/subscription.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
class Subscription < ApplicationRecord
belongs_to :user
belongs_to :subject
delegate :label, :level, :status, :count, :status_updated_at, to: :subject, allow_nil: true
delegate :label, :level, :status, :count, :status_updated_at, :collect_at, :complete_at, to: :subject, allow_nil: true

attr_accessor :skip_notify_subscription

Expand Down
2 changes: 1 addition & 1 deletion app/services/analyze_group_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def submit_task_status
end
count = repos_count

message = { label: @project_name, level: @level, status: Subject.task_status_converter(task_resp['status']), count: count, status_updated_at: DateTime.now.iso8601 }
message = { label: @project_name, level: @level, status: Subject.task_status_converter(task_resp['status']), count: count, status_updated_at: DateTime.now.utc.iso8601 }

RabbitMQ.publish(SUBSCRIPTION_QUEUE, message) if count > 0
{ status: task_resp['status'], message: I18n.t('analysis.task.pending') }
Expand Down
2 changes: 1 addition & 1 deletion app/services/analyze_server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def submit_task_status
)
end

message = { label: @repo_url, level: 'repo', status: Subject.task_status_converter(task_resp['status']), count: 1, status_updated_at: DateTime.now.iso8601 }
message = { label: @repo_url, level: 'repo', status: Subject.task_status_converter(task_resp['status']), count: 1, status_updated_at: DateTime.now.utc.iso8601 }
RabbitMQ.publish(SUBSCRIPTION_QUEUE, message)
{ status: task_resp['status'], message: I18n.t('analysis.task.pending') }
rescue => ex
Expand Down
10 changes: 9 additions & 1 deletion app/workers/subscriptions_update_worker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,15 @@ def work(msg)
count: count
)
end
subject.status != status && subject.update!(status: status)
if subject.status != status
update_attributes = { status: status, status_updated_at: status_updated_at }
if status == Subject::PROGRESS
update_attributes.merge!({ collect_at: status_updated_at })
elsif status == Subject::COMPLETE
update_attributes.merge!({ complete_at: status_updated_at })
end
subject.update!(update_attributes)
end

if subject.status == Subject::COMPLETE
subject.subscriptions.includes(:user).each do |subscription|
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class AddCollectAtAndCompleteAtToSubjects < ActiveRecord::Migration[7.0]
def change
add_column :subjects, :collect_at, :datetime
add_column :subjects, :complete_at, :datetime
end
end
2 changes: 2 additions & 0 deletions spec/models/subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
# status_updated_at :datetime
# created_at :datetime not null
# updated_at :datetime not null
# collect_at :datetime
# complete_at :datetime
#
# Indexes
#
Expand Down