Skip to content

Commit

Permalink
Merge pull request #680 from shaojunda/shaojunda-add-maintenance-info…
Browse files Browse the repository at this point in the history
…-api
  • Loading branch information
shaojunda authored Jul 8, 2020
2 parents 6a4c09e + 878c3b0 commit f97746e
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
4 changes: 4 additions & 0 deletions app/models/statistic_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions app/serializers/statistic_serializer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions doc/api.raml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}

Expand Down Expand Up @@ -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:
Expand Down
20 changes: 20 additions & 0 deletions lib/tasks/set_maintenance_info.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
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]).utc
dry_run = args[:dry_run] || "true"
if args[:end_at] != "nil"
end_at = Time.parse(args[:end_at]).utc
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.to_i.to_s, end_at: end_at.to_i.to_s }
puts "inf: #{info}"
Rails.cache.write("maintenance_info", info)
end
end
14 changes: 13 additions & 1 deletion public/api_doc.html
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,7 @@
}
]
}
</code></pre></div></div></div></div></div></div></div></div><div class="panel panel-white resource-modal"><div class="panel-heading"><h4 class="panel-title"><a class="collapsed" data-toggle="collapse" href="#panel_statistics__info_name_"><span class="parent">/statistics</span>/{info_name}</a> <span class="methods"><a href="#statistics__info_name__get"><span class="badge badge_get">get</span></a></span></h4></div><div id="panel_statistics__info_name_" class="panel-collapse collapse"><div class="panel-body"><div class="list-group"><div onclick="window.location.href = '#statistics__info_name__get'" class="list-group-item"><span class="badge badge_get">get</span><div class="method_description"><p>Returns the specific statistic info</p></div><div class="clearfix"></div></div></div></div></div><div class="modal fade" tabindex="0" id="statistics__info_name__get"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title" id="myModalLabel"><span class="badge badge_get">get</span> <span class="parent">/statistics</span>/{info_name}</h4></div><div class="modal-body"><div class="alert alert-info"><p>Returns the specific statistic info</p></div><ul class="nav nav-tabs"><li class="active"><a href="#statistics__info_name__get_request" data-toggle="tab">Request</a></li><li><a href="#statistics__info_name__get_response" data-toggle="tab">Response</a></li></ul><div class="tab-content"><div class="tab-pane active" id="statistics__info_name__get_request"><h3>URI Parameters</h3><ul><li><strong>info_name</strong>: <em><span class="required">required</span>(string)</em><p>The statistic info name</p></li></ul></div><div class="tab-pane" id="statistics__info_name__get_response"><h2>HTTP status code <a href="http://httpstatus.es/200" target="_blank">200</a></h2><h3>Body</h3><p><strong>Media type</strong>: application/vnd.api+json</p><p><strong>Type</strong>: object</p><strong>Properties</strong><ul><li><strong>data</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>tip_block_number</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>average_block_time</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>current_epoch_difficulty</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>hash_rate</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>blockchain_info</strong>: <em><span class="required">required</span>(object)</em><ul></ul></li><li><strong>address_balance_ranking</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>ranking</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>address</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>balance</strong>: <em><span class="required">required</span>(string)</em></li></ul></li></ul></li></ul><p><strong>Examples</strong>:</p><div class="examples"><p><strong>tip_block_number</strong>:<br></p><pre><code>{
</code></pre></div></div></div></div></div></div></div></div><div class="panel panel-white resource-modal"><div class="panel-heading"><h4 class="panel-title"><a class="collapsed" data-toggle="collapse" href="#panel_statistics__info_name_"><span class="parent">/statistics</span>/{info_name}</a> <span class="methods"><a href="#statistics__info_name__get"><span class="badge badge_get">get</span></a></span></h4></div><div id="panel_statistics__info_name_" class="panel-collapse collapse"><div class="panel-body"><div class="list-group"><div onclick="window.location.href = '#statistics__info_name__get'" class="list-group-item"><span class="badge badge_get">get</span><div class="method_description"><p>Returns the specific statistic info</p></div><div class="clearfix"></div></div></div></div></div><div class="modal fade" tabindex="0" id="statistics__info_name__get"><div class="modal-dialog modal-lg"><div class="modal-content"><div class="modal-header"><button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button><h4 class="modal-title" id="myModalLabel"><span class="badge badge_get">get</span> <span class="parent">/statistics</span>/{info_name}</h4></div><div class="modal-body"><div class="alert alert-info"><p>Returns the specific statistic info</p></div><ul class="nav nav-tabs"><li class="active"><a href="#statistics__info_name__get_request" data-toggle="tab">Request</a></li><li><a href="#statistics__info_name__get_response" data-toggle="tab">Response</a></li></ul><div class="tab-content"><div class="tab-pane active" id="statistics__info_name__get_request"><h3>URI Parameters</h3><ul><li><strong>info_name</strong>: <em><span class="required">required</span>(string)</em><p>The statistic info name</p></li></ul></div><div class="tab-pane" id="statistics__info_name__get_response"><h2>HTTP status code <a href="http://httpstatus.es/200" target="_blank">200</a></h2><h3>Body</h3><p><strong>Media type</strong>: application/vnd.api+json</p><p><strong>Type</strong>: object</p><strong>Properties</strong><ul><li><strong>data</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>tip_block_number</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>average_block_time</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>current_epoch_difficulty</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>hash_rate</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>blockchain_info</strong>: <em><span class="required">required</span>(object)</em><ul></ul></li><li><strong>address_balance_ranking</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>ranking</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>address</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>balance</strong>: <em><span class="required">required</span>(string)</em></li></ul></li><li><strong>maintenance_info"</strong>: <em><span class="required">required</span>(object)</em><ul><li><strong>stat_at</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>end_at</strong>: <em><span class="required">required</span>(string)</em></li></ul></li></ul></li></ul><p><strong>Examples</strong>:</p><div class="examples"><p><strong>tip_block_number</strong>:<br></p><pre><code>{
"data": {
"id": "1",
"type": "statistic_info",
Expand Down Expand Up @@ -1208,6 +1208,18 @@
}
}
}
</code></pre><p><strong>maintenance_info</strong>:<br></p><pre><code>{
"data": {
"id": "1594105429",
"type": "statistic",
"attributes": {
"maintenance_info": {
"start_at": "1591632000",
"end_at": "1591639200"
}
}
}
}
</code></pre></div><h2>HTTP status code <a href="http://httpstatus.es/404" target="_blank">404</a></h2><h3>Body</h3><p><strong>Media type</strong>: application/vnd.api+json</p><p><strong>Type</strong>: object</p><strong>Properties</strong><ul><li><strong>message</strong>: <em><span class="required">required</span>(string)</em></li><li><strong>errors</strong>: <em><span class="required">required</span>(array of error)</em><p><strong>Items</strong>: error</p><div class="items"><ul><li><strong>id</strong>: <em><span class="required">required</span>(string)</em><p>A unique identifier for the specific instance of the error</p></li><li><strong>code</strong>: <em><span class="required">required</span>(string)</em><p>an application-specific error code</p></li><li><strong>status</strong>: <em><span class="required">required</span>(string)</em><p>the HTTP status code applicable to this problem</p></li><li><strong>title</strong>: <em><span class="required">required</span>(string)</em><p>a short, human-readable summary of the problem</p></li><li><strong>detail</strong>: <em><span class="required">required</span>(string)</em><p>A more in-depth, human-readable description of the error and how to resolve it</p></li><li><strong>href</strong>: <em><span class="required">required</span>(string)</em><p>A URL that the developer can use to learn more about the issue</p></li></ul></div></li></ul><p><strong>Example</strong>:</p><div class="examples"><pre><code>{
"message": "Record Not Found",
"errors": [
Expand Down

0 comments on commit f97746e

Please sign in to comment.