diff --git a/app.json b/app.json new file mode 100644 index 0000000..8595c6a --- /dev/null +++ b/app.json @@ -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.com/api_keys", + "value": "", + "required": true + } + } +} diff --git a/bin/setup b/bin/setup new file mode 100755 index 0000000..70366f4 --- /dev/null +++ b/bin/setup @@ -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 diff --git a/pd2pg.rb b/pd2pg.rb index c78db83..763a7b1 100644 --- a/pd2pg.rb +++ b/pd2pg.rb @@ -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) @@ -236,4 +236,4 @@ def refresh end end -PG2PD.new.refresh +PD2PG.new.refresh