Skip to content

Commit

Permalink
mais milhoes
Browse files Browse the repository at this point in the history
  • Loading branch information
nofxx committed Nov 19, 2008
1 parent dd19d1a commit d2919bc
Show file tree
Hide file tree
Showing 33 changed files with 1,852 additions and 16 deletions.
2 changes: 2 additions & 0 deletions app/models/comment.rb
@@ -1,2 +1,4 @@
class Comment < ActiveRecord::Base
belongs_to :pkg
belongs_to :user
end
1 change: 1 addition & 0 deletions app/models/install.rb
@@ -1,2 +1,3 @@
class Install < ActiveRecord::Base
belongs_to :pkg
end
1 change: 1 addition & 0 deletions app/models/karma.rb
@@ -1,2 +1,3 @@
class Karma < ActiveRecord::Base
belongs_to :pkg
end
5 changes: 5 additions & 0 deletions app/models/pkg.rb
@@ -1,2 +1,7 @@
class Pkg < ActiveRecord::Base
belongs_to :maitainer, :foreign_key => :mainteiner_id, :class_name => "User"
has_many :versions, :dependent => :destroy
has_many :installs, :dependent => :destroy
has_many :comments, :dependent => :destroy
has_many :karmas, :dependent => :destroy
end
10 changes: 7 additions & 3 deletions app/models/user.rb
Expand Up @@ -5,6 +5,10 @@ class User < ActiveRecord::Base
include Authentication::ByPassword
include Authentication::ByCookieToken
include Authorization::StatefulRoles

has_many :pkgs, :foreign_key => :maintainer_id, :dependent => :nullify
has_many :comments, :dependent => :destroy

validates_presence_of :login
validates_length_of :login, :within => 3..40
validates_uniqueness_of :login
Expand All @@ -18,7 +22,7 @@ class User < ActiveRecord::Base
validates_uniqueness_of :email
validates_format_of :email, :with => Authentication.email_regex, :message => Authentication.bad_email_message



# HACK HACK HACK -- how to do attr_accessible from here?
# prevents a user from submitting a crafted form that bypasses activation
Expand All @@ -29,7 +33,7 @@ class User < ActiveRecord::Base

# Authenticates a user by their login name and unencrypted password. Returns the user or nil.
#
# uff. this is really an authorization, not authentication routine.
# uff. this is really an authorization, not authentication routine.
# We really need a Dispatch Chain here or something.
# This will also let us return a human error message.
#
Expand All @@ -48,7 +52,7 @@ def email=(value)
end

protected

def make_activation_code
self.deleted_at = nil
self.activation_code = self.class.make_token
Expand Down
1 change: 1 addition & 0 deletions app/models/version.rb
@@ -1,2 +1,3 @@
class Version < ActiveRecord::Base
belongs_to :pkg
end
48 changes: 48 additions & 0 deletions config/backgroundrb.yml
@@ -0,0 +1,48 @@
---
:backgroundrb:
:ip: 0.0.0.0
:port: 11006
:log: foreground # foreground mode,print log messages on console
# :environment: production

:development:
:backgroundrb:
:log: foreground
# turn this off if your application doesn't use backgroundrb's persistent/enqueued tasks system
:persistent_disabled: false
# the time (seconds) between
:persistent_delay: 20
# foreground mode,print log messages on console

:production:
:backgroundrb:
# :port: 22222 # use port 22222
:lazy_load: true # do not load models eagerly
:debug_log: false # disable log workers and other logging

:schedules:
:fetch_worker:
:arch:
:trigger_args: * * */1 * * * *

# :backgroundrb:
# :ip: 0.0.0.0 #ip on which backgroundrb server is running
# :port: 11006 #port on which backgroundrb server is running
# :environment: production # rails environment loaded, defaults to development
# :debug_log: true # whether to print debug logs to a seperate worker, defaults to true
# :log: foreground # will print log messages to STDOUT, defaults to seperate log worker
# :result_storage: memcache # store results in a mecache cluster, you also need to specify location of your memcache clusters in next section
#
# :memcache: "10.0.0.1:11211,10.0.0.2:11211" #=> location of mecache clusters seperated by comma
#
# # following section is totally optional, and only useful if you are trying to cluster of backgroundrb server
# # if you do not specify this section backgroundrb will assume that, from rails you are connecting to the
# # backgroundrb server which has been specified in previous section
# :client: "10.0.0.1:11006,10.0.0.2:11007"
#
# # You specify your worker schedules here
# :schedules:
# :foo_worker: # worker name
# :barbar: #worker method
# :trigger_args: */5 * * * * * * #worker schedule
# cheduling section
8 changes: 6 additions & 2 deletions db/migrate/20081119125336_create_pkgs.rb
@@ -1,13 +1,17 @@
class CreatePkgs < ActiveRecord::Migration
def self.up
create_table :pkgs do |t|
t.string :name
t.text :desc
t.string :name, :null => false
t.text :desc, :null => false
t.integer :weight, :null => false, :default => 0
t.references :maintainer
t.string :repo

t.timestamps
end

add_index :pkgs, :name
add_index :pkgs, :maitainer
end

def self.down
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20081119130130_create_versions.rb
@@ -1,8 +1,8 @@
class CreateVersions < ActiveRecord::Migration
def self.up
create_table :versions do |t|
t.references :pkg
t.string :name
t.references :pkg, :null => false
t.string :name, :null => false
t.text :desc

t.timestamps
Expand Down
6 changes: 3 additions & 3 deletions db/migrate/20081119130210_create_comments.rb
@@ -1,9 +1,9 @@
class CreateComments < ActiveRecord::Migration
def self.up
create_table :comments do |t|
t.references :user
t.references :pkg
t.text :content
t.references :user, :null => false
t.references :pkg, :null => false
t.text :content, :null => false

t.timestamps
end
Expand Down
8 changes: 4 additions & 4 deletions db/migrate/20081119130246_create_karmas.rb
@@ -1,10 +1,10 @@
class CreateKarmas < ActiveRecord::Migration
def self.up
create_table :karmas do |t|
t.references :pkg
t.integer :value
t.references :user
t.references :version
t.references :pkg, :null => false
t.integer :value, :null => false
t.references :user, :null => false
t.references :version, :null => false

t.timestamps
end
Expand Down
4 changes: 2 additions & 2 deletions db/migrate/20081119130423_create_installs.rb
@@ -1,8 +1,8 @@
class CreateInstalls < ActiveRecord::Migration
def self.up
create_table :installs do |t|
t.references :pkg
t.boolean :code
t.references :pkg, :null => false
t.boolean :code, :null => false

t.timestamps
end
Expand Down
27 changes: 27 additions & 0 deletions db/migrate/20081119131136_create_backgroundrb_queue_table.rb
@@ -0,0 +1,27 @@
class CreateBackgroundrbQueueTable < ActiveRecord::Migration
def self.up
create_table :bdrb_job_queues do |t|
t.column :args, :binary
t.column :worker_name, :string
t.column :worker_method, :string
t.column :job_key, :string
t.column :taken, :int
t.column :finished, :int
t.column :timeout, :int
t.column :priority, :int
t.column :submitted_at, :datetime
t.column :started_at, :datetime
t.column :finished_at, :datetime
t.column :archived_at, :datetime
t.column :tag, :string
t.column :submitter_info, :string
t.column :runner_info, :string
t.column :worker_key, :string
t.column :scheduled_at, :datetime
end
end

def self.down
drop_table :bdrb_job_queues
end
end
19 changes: 19 additions & 0 deletions lib/arch/arch_fetcher.rb
@@ -0,0 +1,19 @@
#
# Pacman fetcher.... simple thing that could work?
#

module Arch
module Fetcher

def self.get_list
text_list = system("pacman -Sl")

end




end


end
30 changes: 30 additions & 0 deletions lib/workers/fetch_worker.rb
@@ -0,0 +1,30 @@
class FetchWorker < BackgrounDRb::MetaWorker
set_worker_name :fetch_worker
def create(args = nil)
# this method is called, when worker is loaded for the first time
end


def update_pkgs(pkgs)

for pkg in pkgs

Pkg.create!(:name => pkg[:name])


end



end



def arch
update_pkgs(Arch::Fetcher.run!)
end




end
7 changes: 7 additions & 0 deletions lib/workers/git_worker.rb
@@ -0,0 +1,7 @@
class GitWorker < BackgrounDRb::MetaWorker
set_worker_name :git_worker
def create(args = nil)
# this method is called, when worker is loaded for the first time
end
end

39 changes: 39 additions & 0 deletions script/backgroundrb
@@ -0,0 +1,39 @@
#!/usr/bin/env ruby

RAILS_HOME = File.expand_path(File.join(File.dirname(__FILE__),".."))
BDRB_HOME = File.join(RAILS_HOME,"vendor","plugins","backgroundrb")
WORKER_ROOT = File.join(RAILS_HOME,"lib","workers")
WORKER_LOAD_ENV = File.join(RAILS_HOME,"script","load_worker_env")

["server","server/lib","lib","lib/backgroundrb"].each { |x| $LOAD_PATH.unshift(BDRB_HOME + "/#{x}")}
$LOAD_PATH.unshift(WORKER_ROOT)

require "rubygems"
require "yaml"
require "erb"
require "logger"
require "packet"
require "optparse"

require "bdrb_config"
require RAILS_HOME + "/config/boot"
require "active_support"

BackgrounDRb::Config.parse_cmd_options ARGV
BDRB_CONFIG = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")

require RAILS_HOME + "/config/environment"
require "bdrb_job_queue"
require "backgroundrb_server"

PID_FILE = "#{RAILS_HOME}/tmp/pids/backgroundrb_#{BDRB_CONFIG[:backgroundrb][:port]}.pid"
SERVER_LOGGER = "#{RAILS_HOME}/log/backgroundrb_debug_#{BDRB_CONFIG[:backgroundrb][:port]}.log"

daemon = BackgrounDRb::StartStop.new

case ARGV[0]
when 'start'; daemon.start
when 'stop'; daemon.stop()
else; BackgrounDRb::MasterProxy.new()
end

25 changes: 25 additions & 0 deletions script/load_worker_env.rb
@@ -0,0 +1,25 @@
#!/usr/bin/env ruby

RAILS_HOME = File.expand_path(File.join(File.dirname(__FILE__),".."))
BDRB_HOME = File.join(RAILS_HOME,"vendor","plugins","backgroundrb")

["server","server/lib","lib","lib/backgroundrb"].each { |x| $LOAD_PATH.unshift(BDRB_HOME + "/#{x}")}

$LOAD_PATH.unshift(File.join(RAILS_HOME,"lib","workers"))

require "yaml"
require "erb"
require "logger"
require "optparse"
require "bdrb_config"
require RAILS_HOME + "/config/boot"
require "active_support"

BDRB_CONFIG = BackgrounDRb::Config.read_config("#{RAILS_HOME}/config/backgroundrb.yml")

if !(::Packet::WorkerRunner::WORKER_OPTIONS[:worker_env] == false)
require RAILS_HOME + "/config/environment"
ActiveRecord::Base.allow_concurrency = true
end
require "backgroundrb_server"

5 changes: 5 additions & 0 deletions spec/spec.opts
@@ -0,0 +1,5 @@
--colour
--loadby random
--format progress
--reverse
--diff

0 comments on commit d2919bc

Please sign in to comment.