forked from diaspora/diaspora-project-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Dennis Schubert
committed
Dec 11, 2014
1 parent
96ccc44
commit 149f4fb
Showing
16 changed files
with
341 additions
and
7 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
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#!/usr/bin/env ruby | ||
require_relative '../config/environment' | ||
Planet::CLI.new |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Planet.configure do |config| | ||
config.interval = 10 | ||
config.log_path = STDOUT | ||
config.log_level = :debug | ||
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,21 @@ | ||
class CreatePlanetTables < ActiveRecord::Migration | ||
def change | ||
create_table :planet_feeds do |t| | ||
t.string :url, limit: 800 | ||
t.string :site_url, limit: 800 | ||
t.string :title | ||
t.timestamps | ||
end | ||
|
||
create_table :planet_entries do |t| | ||
t.string :title | ||
t.string :author | ||
t.string :url, limit: 800 | ||
t.string :entry_id, limit: 800 | ||
t.text :body | ||
t.datetime :published_at | ||
t.references :feed | ||
t.timestamps | ||
end | ||
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
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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
require 'logger' | ||
|
||
module Planet | ||
require 'planet/cli' | ||
require 'planet/config' | ||
require 'planet/models' | ||
require 'planet/feed_container' | ||
require 'planet/fetcher' | ||
|
||
class << self | ||
def config | ||
(@config ||= Config.new).tap {|config| | ||
yield config if block_given? | ||
} | ||
end | ||
alias_method :configure, :config | ||
|
||
def logger | ||
(@logger ||= Logger.new config.log_path).tap {|logger| | ||
logger.level = config.log_level | ||
} | ||
end | ||
end | ||
|
||
def self.table_name_prefix | ||
'planet_' | ||
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,39 @@ | ||
require 'trollop' | ||
|
||
module Planet | ||
class CLI | ||
def initialize | ||
parse_options | ||
run | ||
end | ||
|
||
private | ||
|
||
def parse_options | ||
@options = Trollop.options do | ||
banner "Planet fetcher, updates the feeds" | ||
opt :interval, "Dispatch update every n minutes", type: :integer | ||
opt :logfile, "Path to logfile", type: :string | ||
opt :verbosity, "Verbosity (debug, info, warn, error)", type: :string | ||
end | ||
end | ||
|
||
def run | ||
Planet.logger.info "Entering mainloop" | ||
loop do | ||
fetch_new_entries | ||
Planet.logger.info { "Sleeping for #{Planet.config.interval} minutes" } | ||
sleep Planet.config.interval*60 | ||
end | ||
end | ||
|
||
def fetch_new_entries | ||
Planet.logger.info "Fetching new entries" | ||
fetcher.run | ||
end | ||
|
||
def fetcher | ||
@fetcher ||= Fetcher.new | ||
end | ||
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,28 @@ | ||
require 'logger' | ||
|
||
module Planet | ||
class Config | ||
attr_accessor :interval | ||
attr_accessor :log_path | ||
attr_writer :log_level | ||
|
||
alias_method :configure, :tap | ||
|
||
def initialize | ||
self.interval = 10 | ||
self.log_level = :info | ||
self.log_path = STDOUT | ||
end | ||
|
||
def log_level | ||
@log_level = @log_level.to_sym if @log_level.is_a? String | ||
case @log_level | ||
when Symbol | ||
{debug: Logger::DEBUG, error: Logger::ERROR, fatal: Logger::FATAL, | ||
info: Logger::INFO, warn: Logger::WARN}[@log_level] | ||
when Fixnum | ||
@log_level | ||
end | ||
end | ||
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,3 @@ | ||
module Planet | ||
FeedContainer = Struct.new(:feed, :model) | ||
end |
Oops, something went wrong.