From f7f6844f43dbeb66d4ca02d2e536dc9fa88a2ea9 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Tue, 7 Jul 2020 14:01:56 +0800 Subject: [PATCH 01/10] feat: add maintenance info to statistic info --- app/models/statistic_info.rb | 4 ++++ app/serializers/statistic_serializer.rb | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/app/models/statistic_info.rb b/app/models/statistic_info.rb index f7bef85d9..7f36c52cc 100644 --- a/app/models/statistic_info.rb +++ b/app/models/statistic_info.rb @@ -81,6 +81,10 @@ def blockchain_info end end + def maintenance_info + Rails.cache.fetch("maintenance_info") + end + private attr_reader :hash_rate_statistical_interval, :average_block_time_interval diff --git a/app/serializers/statistic_serializer.rb b/app/serializers/statistic_serializer.rb index 6aabc795f..1cfe76c43 100644 --- a/app/serializers/statistic_serializer.rb +++ b/app/serializers/statistic_serializer.rb @@ -28,4 +28,8 @@ class StatisticSerializer attribute :address_balance_ranking, if: Proc.new { |_record, params| params && params[:info_name] == "address_balance_ranking" } + + attribute :maintenance_info, if: Proc.new { |_record, params| + params && params[:info_name] == "maintenance_info" + } end From d02720cccb7d2c9d50d7c3831b646557eba914e1 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Tue, 7 Jul 2020 14:04:46 +0800 Subject: [PATCH 02/10] feat: add task to set maintenance info --- lib/tasks/set_maintenance_info.rake | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 lib/tasks/set_maintenance_info.rake diff --git a/lib/tasks/set_maintenance_info.rake b/lib/tasks/set_maintenance_info.rake new file mode 100644 index 000000000..24164a0c3 --- /dev/null +++ b/lib/tasks/set_maintenance_info.rake @@ -0,0 +1,19 @@ +desc "Usage: RAILS_ENV=production bundle exec rake 'set_maintenance_info[2020-06-09 00:00:00, nil]'" +task :set_maintenance_info, [:start_at, :end_at, :dry_run] => :environment do |_, args| + raise "please input start at" if args[:start_at].blank? + + start_at = Time.parse(args[:start_at]) + dry_run = args[:dry_run] || "true" + if args[:end_at] != "nil" + end_at = Time.parse(args[:end_at]) + else + end_at = start_at + 2.hours + end + if dry_run == "true" + puts "start_at: #{start_at}" + puts "end_at: #{end_at}" + else + info = { start_at: start_at, end_at: end_at } + Rails.cache.write("maintenance_info", info) + end +end From 6671907758d4d4e1899d3ed2ee1c557b3c7191f0 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Tue, 7 Jul 2020 14:40:08 +0800 Subject: [PATCH 03/10] chore: use timestamp on maintenance info --- lib/tasks/set_maintenance_info.rake | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/tasks/set_maintenance_info.rake b/lib/tasks/set_maintenance_info.rake index 24164a0c3..c7ba6a361 100644 --- a/lib/tasks/set_maintenance_info.rake +++ b/lib/tasks/set_maintenance_info.rake @@ -2,10 +2,10 @@ desc "Usage: RAILS_ENV=production bundle exec rake 'set_maintenance_info[2020-06 task :set_maintenance_info, [:start_at, :end_at, :dry_run] => :environment do |_, args| raise "please input start at" if args[:start_at].blank? - start_at = Time.parse(args[:start_at]) + start_at = Time.parse(args[:start_at]).utc dry_run = args[:dry_run] || "true" if args[:end_at] != "nil" - end_at = Time.parse(args[:end_at]) + end_at = Time.parse(args[:end_at]).utc else end_at = start_at + 2.hours end @@ -13,7 +13,8 @@ task :set_maintenance_info, [:start_at, :end_at, :dry_run] => :environment do |_ puts "start_at: #{start_at}" puts "end_at: #{end_at}" else - info = { start_at: start_at, end_at: end_at } + info = { start_at: start_at.to_i, end_at: end_at.to_i } + puts "inf: #{info}" Rails.cache.write("maintenance_info", info) end end From 8aa4fe7a40974df1237d1e8b7267af6ebd70c4d1 Mon Sep 17 00:00:00 2001 From: shaojunda Date: Tue, 7 Jul 2020 15:18:39 +0800 Subject: [PATCH 04/10] doc: add maintenance_info --- doc/api.raml | 28 ++++++++++++++++++++++++++++ public/api_doc.html | 14 +++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/doc/api.raml b/doc/api.raml index 2a6130096..24953682b 100644 --- a/doc/api.raml +++ b/doc/api.raml @@ -546,6 +546,21 @@ types: "address_balance_ranking": { type: "address_balance_ranking" } + "maintenance_info": { + type: "maintenance_info" + } + } + } + + maintenance_info: { + type: object, + properties: { + "stat_at": { + type: "string" + }, + "end_at": { + type: "string" + } } } @@ -2475,6 +2490,19 @@ types: } } } + maintenance_info: | + { + "data": { + "id": "1594105429", + "type": "statistic", + "attributes": { + "maintenance_info": { + "start_at": "1591632000", + "end_at": "1591639200" + } + } + } + } 404: body: application/vnd.api+json: diff --git a/public/api_doc.html b/public/api_doc.html index 62071c180..1fd2f10a6 100644 --- a/public/api_doc.html +++ b/public/api_doc.html @@ -1083,7 +1083,7 @@ } ] } -
get

Returns the specific statistic info

get

Returns the specific statistic info

get

Returns the specific statistic info

get

Returns the specific statistic info