Skip to content
This repository was archived by the owner on Apr 8, 2021. It is now read-only.

Add app.json and allow to configure through config vars #5

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
28 changes: 28 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "Pd2pg",
"description": "Pager duty info in a local postgres database",
"keywords": [
"small",
"sharp",
"tool"
],
"addons": [
"heroku-postgresql:standard-0"
],
"scripts": {
"postdeploy": "bundle exec bin/setup"
},
"env": {
"LANG": "en_US.UTF-8",
"PAGERDUTY_SUBDOMAIN": {
"description": "your-company subdomain",
"value": "",
"required": true
},
"PAGERDUTY_API_KEY": {
"description": "a read-only API key from https://<PAGERDUTY_SUBDOMAIN>.pagerduty.com/api_keys",
"value": "",
"required": true
}
}
}
12 changes: 12 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/usr/bin/env ruby
require "sequel"
done = false
while !done
begin
db = Sequel.connect(ENV['DATABASE_URL'])
db.run(File.read('schema.sql'))
done = true
rescue Sequel::DatabaseConnectionError => e
puts "DB is not ready"
end
end
12 changes: 6 additions & 6 deletions pd2pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
# Ensure all data processing and storage is in UTC.
ENV["TZ"] = "UTC"

class PG2PD
class PD2PG
# Largest page size allowed.
PAGINATION_LIMIT = 100
PAGINATION_LIMIT = (ENV["PAGINATION_LIMIT"] || 100).to_i

# Rewind by ~1h when doing incremental updates, to ensure we don't
# miss anything.
INCREMENTAL_BUFFER = 60*60
INCREMENTAL_BUFFER = (ENV["INCREMENTAL_BUFFER"] || 60*60).to_i

# Apply incremental updates atomically for ~24 hour windows, instead
# of trying to fetch all of history and apply it at once.
INCREMENTAL_WINDOW = 60*60*24
INCREMENTAL_WINDOW = (ENV["INCREMENTAL_WINDOW"] || 60*60*24).to_i

# Earliest time PagerDuty data could be available.
PAGERDUTY_EPOCH = Time.parse("2009-01-01T00:00Z")
PAGERDUTY_EPOCH = Time.parse(ENV["PAGERDUTY_EPOCH"] || "2009-01-01T00:00Z")

# Reads required config from environment variables.
def env!(k)
Expand Down Expand Up @@ -236,4 +236,4 @@ def refresh
end
end

PG2PD.new.refresh
PD2PG.new.refresh