-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Sidekiq to tweet announcements * Add staging env * Sidekiq number of workers * Correct twitter env vars * Add deployment notes
- Loading branch information
Showing
12 changed files
with
124 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web: ./app | ||
worker: ./sidekiq -c 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,21 @@ | ||
require "amber" | ||
require "yaml" | ||
require "sidekiq" | ||
require "multi_auth" | ||
require "option_parser" | ||
|
||
OptionParser.parse! do |opts| | ||
opts.on("-p PORT", "--port PORT", "") do |opt_port| | ||
end | ||
end | ||
AMBER_PORT = ENV["PORT"]? || 3008 | ||
AMBER_ENV = ENV["AMBER_ENV"]? || "development" | ||
|
||
AMBER_ENV = ENV["AMBER_ENV"]? || "development" | ||
SITE = YAML.parse(File.read "config/site.yml")[AMBER_ENV] | ||
Sidekiq::Client.default_context = Sidekiq::Client::Context.new | ||
MultiAuth.config("github", ENV.fetch("GITHUB_ID", ""), ENV.fetch("GITHUB_SECRET", "")) | ||
|
||
Amber::Server.instance.config do |app| | ||
app_path = __FILE__ | ||
app.name = "Crystal [ANN] web application." | ||
app.port = (ENV["PORT"]? || "3008").to_i | ||
app.port = AMBER_PORT.to_i | ||
app.env = AMBER_ENV.to_s | ||
app.log = ::Logger.new(STDOUT) | ||
app.log.level = ::Logger::INFO | ||
end | ||
|
||
require "yaml" | ||
SITE = YAML.parse(File.read "config/site.yml")[AMBER_ENV] | ||
|
||
require "multi_auth" | ||
MultiAuth.config("github", ENV.fetch("GITHUB_ID", ""), ENV.fetch("GITHUB_SECRET", "")) | ||
|
||
require "micrate" | ||
require "pg" | ||
if AMBER_ENV != "development" | ||
puts "Migrating data" | ||
Micrate::DB.connection_url = ENV["DATABASE_URL"]? | ||
Micrate::Cli.run_up | ||
puts "Migration finished" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,17 @@ | ||
require "amber" | ||
require "micrate" | ||
require "pg" | ||
require "./controllers/**" | ||
require "./mailers/**" | ||
require "./models/**" | ||
require "./views/**" | ||
require "../config/*" | ||
|
||
if AMBER_ENV != "development" | ||
puts "Migrating data" | ||
Micrate::DB.connection_url = ENV["DATABASE_URL"]? | ||
Micrate::Cli.run_up | ||
puts "Migration finished" | ||
end | ||
|
||
Amber::Server.instance.run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -76,4 +76,8 @@ class Announcement < Granite::ORM | |
def user | ||
User.find(user_id) | ||
end | ||
|
||
def path | ||
"/announcements/#{id}" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "../config/application" | ||
require "./workers/**" | ||
require "sidekiq/cli" | ||
|
||
cli = Sidekiq::CLI.new | ||
server = cli.configure { } | ||
cli.run(server) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
require "sidekiq" | ||
require "twitter" | ||
require "../models/announcement" | ||
|
||
module Workers | ||
class TweetAnnouncement | ||
include Sidekiq::Worker | ||
|
||
def perform(id : Int64) | ||
if announcement = Announcement.find(id) | ||
tweet(announcement) | ||
end | ||
end | ||
|
||
def twitter_client | ||
@twitter_client ||= | ||
Twitter::REST::Client.new ENV["TWITTER_CONSUMER_KEY"], | ||
ENV["TWITTER_CONSUMER_SECRET"], | ||
ENV["TWITTER_ACCESS_TOKEN"], | ||
ENV["TWITTER_ACCESS_TOKEN_SECRET"] | ||
end | ||
|
||
def tweet(announcement) | ||
logger.error "Tweeting Announcement ##{announcement.id}" | ||
status = tweet_template announcement | ||
twitter_client.post("/1.1/statuses/update.json", {"status" => status}) | ||
rescue e | ||
logger.error "Unable to tweet Announcement ##{announcement.id} (#{status})" | ||
logger.error "Reason: #{e.message}" | ||
end | ||
|
||
def tweet_template(announcement) | ||
site_url = SITE["url"] | ||
"#{announcement.title} #{site_url}#{announcement.path} #crystallang" | ||
end | ||
end | ||
end |