pgq_web 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +29 -0
  3. data/Rakefile +40 -0
  4. data/app/assets/images/glyphicons-halflings-white.png +0 -0
  5. data/app/assets/images/glyphicons-halflings.png +0 -0
  6. data/app/assets/javascripts/bootstrap.min.js +6 -0
  7. data/app/assets/javascripts/pgq_web/application.js +16 -0
  8. data/app/assets/stylesheets/pgq_web/application.css +16 -0
  9. data/app/assets/stylesheets/pgq_web/bootstrap-responsive.min.css +9 -0
  10. data/app/assets/stylesheets/pgq_web/bootstrap.min.css +9 -0
  11. data/app/controllers/pgq_web/application_controller.rb +4 -0
  12. data/app/controllers/pgq_web/pgq_controller.rb +186 -0
  13. data/app/helpers/pgq_web/application_helper.rb +4 -0
  14. data/app/helpers/pgq_web/pgq_helper.rb +22 -0
  15. data/app/models/pgq_web/watcher.rb +4 -0
  16. data/app/views/layouts/pgq_web/application.html.erb +14 -0
  17. data/app/views/layouts/pgq_web/pgq.html.erb +18 -0
  18. data/app/views/pgq_web/pgq/_error.haml +21 -0
  19. data/app/views/pgq_web/pgq/_menu.haml +15 -0
  20. data/app/views/pgq_web/pgq/_pags.haml +3 -0
  21. data/app/views/pgq_web/pgq/_pending_events_res.haml +4 -0
  22. data/app/views/pgq_web/pgq/delete.js.erb +1 -0
  23. data/app/views/pgq_web/pgq/errors.haml +21 -0
  24. data/app/views/pgq_web/pgq/errors_list.haml +13 -0
  25. data/app/views/pgq_web/pgq/index.haml +22 -0
  26. data/app/views/pgq_web/pgq/pending_events_count.js.erb +1 -0
  27. data/app/views/pgq_web/pgq/pending_list.haml +20 -0
  28. data/app/views/pgq_web/pgq/retry.js.erb +1 -0
  29. data/config/initializers/databases.rb +8 -0
  30. data/config/initializers/will_paginate_init.rb +32 -0
  31. data/config/routes.rb +4 -0
  32. data/lib/pgq_web/engine.rb +5 -0
  33. data/lib/pgq_web/version.rb +3 -0
  34. data/lib/pgq_web.rb +4 -0
  35. data/lib/tasks/pgq_web_tasks.rake +4 -0
  36. data/test/dummy/README.rdoc +261 -0
  37. data/test/dummy/Rakefile +7 -0
  38. data/test/dummy/app/assets/javascripts/application.js +15 -0
  39. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  40. data/test/dummy/app/controllers/application_controller.rb +3 -0
  41. data/test/dummy/app/helpers/application_helper.rb +2 -0
  42. data/test/dummy/app/models/base2.rb +4 -0
  43. data/test/dummy/app/models/pgq/pgq_cleanup.rb +10 -0
  44. data/test/dummy/app/models/pgq/pgq_history.rb +10 -0
  45. data/test/dummy/app/models/pgq/pgq_issues.rb +11 -0
  46. data/test/dummy/app/models/pgq/pgq_pack_files.rb +10 -0
  47. data/test/dummy/app/models/pgq/pgq_places.rb +10 -0
  48. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  49. data/test/dummy/config/application.rb +56 -0
  50. data/test/dummy/config/boot.rb +10 -0
  51. data/test/dummy/config/database.yml +23 -0
  52. data/test/dummy/config/environment.rb +5 -0
  53. data/test/dummy/config/environments/development.rb +37 -0
  54. data/test/dummy/config/environments/production.rb +67 -0
  55. data/test/dummy/config/environments/test.rb +37 -0
  56. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  57. data/test/dummy/config/initializers/inflections.rb +15 -0
  58. data/test/dummy/config/initializers/mime_types.rb +5 -0
  59. data/test/dummy/config/initializers/pgq_configs.rb +6 -0
  60. data/test/dummy/config/initializers/pgq_web_configs.rb +2 -0
  61. data/test/dummy/config/initializers/secret_token.rb +7 -0
  62. data/test/dummy/config/initializers/session_store.rb +8 -0
  63. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/test/dummy/config/locales/en.yml +5 -0
  65. data/test/dummy/config/pgq_development.ini +12 -0
  66. data/test/dummy/config/pgq_development2.ini +12 -0
  67. data/test/dummy/config/queues_list.yml +6 -0
  68. data/test/dummy/config/routes.rb +3 -0
  69. data/test/dummy/config.ru +4 -0
  70. data/test/dummy/db/migrate/20120526095837_create_pack_files_queue.rb +9 -0
  71. data/test/dummy/db/migrate/20120526095903_create_issues_queue.rb +9 -0
  72. data/test/dummy/db/migrate/20120526095928_create_history_queue.rb +9 -0
  73. data/test/dummy/db/migrate/20120526095941_create_cleanup_queue.rb +9 -0
  74. data/test/dummy/db/migrate/20120526095951_create_londiste_queue.rb +9 -0
  75. data/test/dummy/db/migrate/20120526101453_create_places_queue.rb +9 -0
  76. data/test/dummy/db/schema.rb +16 -0
  77. data/test/dummy/log/development.log +16800 -0
  78. data/test/dummy/log/pgq_issues,cleanup.log +1 -0
  79. data/test/dummy/log/pgq_places,cleanup.log +1 -0
  80. data/test/dummy/log/pgq_places,issues.log +7596 -0
  81. data/test/dummy/log/pgqadm_development.log +33 -0
  82. data/test/dummy/log/pgqadm_development2.log +18 -0
  83. data/test/dummy/public/404.html +26 -0
  84. data/test/dummy/public/422.html +26 -0
  85. data/test/dummy/public/500.html +25 -0
  86. data/test/dummy/public/favicon.ico +0 -0
  87. data/test/dummy/script/rails +6 -0
  88. data/test/dummy/spec/models/pgq/pgq_cleanup_spec.rb +8 -0
  89. data/test/dummy/spec/models/pgq/pgq_history_spec.rb +8 -0
  90. data/test/dummy/spec/models/pgq/pgq_issues_spec.rb +8 -0
  91. data/test/dummy/spec/models/pgq/pgq_londiste_spec.rb +8 -0
  92. data/test/dummy/spec/models/pgq/pgq_pack_files_spec.rb +8 -0
  93. data/test/dummy/spec/models/pgq/pgq_places_spec.rb +8 -0
  94. data/test/dummy/tmp/cache/assets/C54/E90/sprockets%2F63fc13315fc6094795932885c00a47f0 +0 -0
  95. data/test/dummy/tmp/cache/assets/C95/1A0/sprockets%2F0d1713ba9492a53952c0b502f420e02f +0 -0
  96. data/test/dummy/tmp/cache/assets/CA2/F20/sprockets%2Ff13754a4804d90a140215fa2e93b764c +0 -0
  97. data/test/dummy/tmp/cache/assets/CB3/2E0/sprockets%2Fcd388695c120aa9281b12659a238e8a8 +0 -0
  98. data/test/dummy/tmp/cache/assets/CC1/F30/sprockets%2Ff86c32e64381a7631af9079b259dc892 +0 -0
  99. data/test/dummy/tmp/cache/assets/CC2/650/sprockets%2F91458fa64c93ba68469353808d0f8cf1 +0 -0
  100. data/test/dummy/tmp/cache/assets/CDC/D60/sprockets%2F68d28c37c45823d428c334fde92c0b00 +0 -0
  101. data/test/dummy/tmp/cache/assets/D40/DB0/sprockets%2F9a36c3c6b93af595c47b1b4d4f02a576 +0 -0
  102. data/test/dummy/tmp/cache/assets/D58/820/sprockets%2F182d963d2083b09e77ffee56f6fe17d8 +0 -0
  103. data/test/dummy/tmp/cache/assets/D5E/200/sprockets%2Faddfb303b307179f50949a9dac5c1b00 +0 -0
  104. data/test/dummy/tmp/cache/assets/D64/380/sprockets%2Fbd2003fa80f2c539b2d195e64108eecf +0 -0
  105. data/test/dummy/tmp/cache/assets/D65/500/sprockets%2F5aff89b97768a5fa63596da7b7749bd6 +0 -0
  106. data/test/dummy/tmp/cache/assets/D79/410/sprockets%2Fcf8d367988a69f26b3fa20f8f3dc1c01 +0 -0
  107. data/test/dummy/tmp/cache/assets/D7B/760/sprockets%2F67db05a77e3337a5d9e26bd79a7fbc37 +0 -0
  108. data/test/dummy/tmp/cache/assets/D94/C90/sprockets%2Fc6d28dc98f2a28e2b0c49cb34320bcb5 +0 -0
  109. data/test/dummy/tmp/cache/assets/DB3/600/sprockets%2F19d09ea3cfc62ad34a00a2c285ccb2a6 +0 -0
  110. data/test/dummy/tmp/cache/assets/DCA/8C0/sprockets%2Ff10ccfec59bb5d112d0e5eb96b2e4748 +0 -0
  111. data/test/dummy/tmp/cache/assets/E2B/BD0/sprockets%2F4a4f94d3220ffaf6eaea86f1aa79bd5a +0 -0
  112. data/test/dummy/tmp/pgqadm_development.pid +1 -0
  113. data/test/dummy/tmp/pgqadm_development2.pid +1 -0
  114. data/test/integration/navigation_test.rb +10 -0
  115. data/test/pgq_web_test.rb +7 -0
  116. data/test/test_helper.rb +15 -0
  117. metadata +349 -0
@@ -0,0 +1,22 @@
1
+ module PgqWeb::PgqHelper
2
+
3
+ def class_menu(act)
4
+ act == params[:action] ? 'active' : ''
5
+ end
6
+
7
+ def status_span(status = :ok)
8
+ case status
9
+ when :ok then content_tag(:span, 'ok', :class => "label label-success")
10
+ when :warn then content_tag(:span, 'warn', :class => "label label-warning")
11
+ when :error then content_tag(:span, 'error', :class => "label label-important")
12
+ when :stopped then content_tag(:span, 'stopped', :class => "label")
13
+ else
14
+ content_tag(:span, 'ok', :class => "label label-success")
15
+ end
16
+ end
17
+
18
+ def human_time(str_time)
19
+ Time.parse(str_time).strftime("%d.%m.%Y %H:%M:%S") rescue '-'
20
+ end
21
+
22
+ end
@@ -0,0 +1,4 @@
1
+ module PgqWeb
2
+ class Watcher
3
+ end
4
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PgqWeb</title>
5
+ <%= stylesheet_link_tag "pgq_web/application", :media => "all" %>
6
+ <%= javascript_include_tag "pgq_web/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,18 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>PgQ Info</title>
5
+ <%= stylesheet_link_tag "pgq_web/application", :media => "all" %>
6
+ <%= javascript_include_tag "pgq_web/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= render :partial => "pgq_web/pgq/menu" %>
12
+
13
+ <div class="container">
14
+ <%= yield %>
15
+ </div>
16
+
17
+ </body>
18
+ </html>
@@ -0,0 +1,21 @@
1
+ - error['ev_failed_reason'] = Pgq::Consumer.coder.load(error['ev_failed_reason'])
2
+ - error['ev_data'] = Pgq::Consumer.coder.load(error['ev_data'])
3
+ - reason = error['ev_failed_reason']
4
+
5
+ %div{:id => "ev_#{error['ev_id']}"}
6
+ %div
7
+ = error['ev_id']
8
+ (#{human_time(error['ev_failed_time'])})
9
+ = link_to_function "[details]", "$('##{"ev_#{error['ev_id']}_det"}').toggle()"
10
+ = link_to "[retry]", {:action => "retry", :queue_name => @queue_name, :consumer_name => @consumer_name, :ev_id => error['ev_id'], :db_index => params[:db_index]}, :remote => true, :title => "Retry failed event"
11
+ = link_to "[delete]", {:action => 'delete', :queue_name => @queue_name, :consumer_name => @consumer_name, :ev_id => error['ev_id'], :db_index => params[:db_index]}, :confirm => "Are you sure, delete event?", :title => "Delete failed event", :remote => true
12
+ %div
13
+ %span{:style => "padding-top:0px; padding-bottom:0px", :class => "alert alert-error"}
14
+ = ":#{error['ev_type']} => (#{reason[:class]}) #{reason[:message]}"
15
+ %div{:id => "ev_#{error['ev_id']}_det", :class => "", :style => "margin-left: 20px; display: none"}
16
+ %div InsertAt: #{human_time error['ev_time']}
17
+ %div FailedAt: #{human_time error['ev_failed_time']}
18
+ %div EventType: #{error['ev_type']}
19
+ %div Data: #{error['ev_data'].join(",")}
20
+ %div Backtrace:
21
+ %div{:style => "margin-left: 20px"}= reason[:backtrace].join("<br>").html_safe
@@ -0,0 +1,15 @@
1
+ %div{:class => "navbar navbar-fixed-top"}
2
+ %div{:class => "navbar-inner"}
3
+ %div{:class => "container"}
4
+ = link_to "PgQ Info", {:action => :index}, :class => "brand"
5
+ %ul{:class => "nav"}
6
+ %li{:class => class_menu('index')}= link_to 'Queues', :action => :index
7
+ %li{:class => class_menu('errors')}= link_to 'Errors', :action => :errors
8
+ - if params[:action] == 'errors_list'
9
+ %li{:class => "active"}= link_to 'Errors List', '#'
10
+ - if params[:action] == 'pending_list'
11
+ %li{:class => "active"}= link_to 'Pending List', '#'
12
+
13
+ %br
14
+ %br
15
+ %br
@@ -0,0 +1,3 @@
1
+ %span On page:
2
+ - [10, 30, 100, 1000].each do |pp|
3
+ = link_to_unless_current pp, params.merge(:per_page => pp)
@@ -0,0 +1,4 @@
1
+ - if @res == '-'
2
+ %i{:class => "icon-ban-circle"}
3
+ - else
4
+ = link_to @res.to_s, {:action => "pending_list", :queue_name => params[:queue_name], :db_index => params[:db_index], :last_event => @last_event.to_i}
@@ -0,0 +1 @@
1
+ $('#<%="ev_#{params['ev_id']}"%>').html('<%= @res %>');
@@ -0,0 +1,21 @@
1
+ %h3 Pgq Errors (#{@info.size})
2
+
3
+ %table{:class => "table table-bordered", :style => "width:600px"}
4
+ %thead
5
+ %tr
6
+ - @keys.each do |column|
7
+ %td{:align => 'center'}= @keys_names[column]
8
+
9
+ %tbody
10
+ - @info.each do |row|
11
+ %tr
12
+ - @keys.each do |key|
13
+ %td{:align => 'center'}
14
+ - case key
15
+ - when 'errors_count'
16
+ = link_to row[key], {:action => "errors_list", :queue_name => row['queue_name'], :consumer_name => row['consumer_name'], :db_index => row['db_index']}, :title => "Go to details"
17
+ - when 'actions'
18
+ %span= link_to '<i class="icon-repeat"></i>'.html_safe, {:action => "retry_all", :consumer_name => row['consumer_name'], :queue_name => row['queue_name'], :db_index => row['db_index']}, :title => "Retry 5000 failed events"
19
+ %span= link_to '<i class="icon-trash"></i>'.html_safe, {:action => 'delete_all', :consumer_name => row['consumer_name'], :queue_name => row['queue_name'], :db_index => row['db_index']}, :confirm => "Are you sure, delete events?", :title => "Delete 5000 failed events"
20
+ - else
21
+ = row[key]
@@ -0,0 +1,13 @@
1
+ %h3 #{params[:queue_name]} errors(#{@errors_count})
2
+
3
+ = render :partial => "pags"
4
+
5
+ = will_paginate @errors
6
+
7
+ %table{:class => "table"}
8
+ - @errors.each do |error|
9
+ %tr
10
+ %td
11
+ = render :partial => 'error', :object => error
12
+
13
+ = will_paginate @errors
@@ -0,0 +1,22 @@
1
+ - @info_groups.each do |((host, db), info_group)|
2
+ %h3 #{db}@#{host} (#{info_group.size})
3
+ %br
4
+
5
+ %table{:class => "table table-bordered"}
6
+ %thead
7
+ %tr
8
+ - @keys.each do |column|
9
+ %td{:align => 'center'}= @keys_names[column]
10
+
11
+ %tbody
12
+ - info_group.each do |row|
13
+ %tr
14
+ - @keys.each do |key|
15
+ %td{:align => "center"}
16
+ - if key == 'pending_events'
17
+ %span= link_to '<i class="icon-time"></i>'.html_safe, {:action => "pending_events_count", :queue_name => row['queue_name'], :db_index => row['db_index']}, {:remote => true, :title => "Load pending events count for queue", :onclick => "$('##{"pe_ev" + row['queue_name']}').html('')"}
18
+ %span{:id => "pe_ev" + row['queue_name']}
19
+ - elsif key == 'status'
20
+ = status_span(row['status'])
21
+ - else
22
+ = row[key]
@@ -0,0 +1 @@
1
+ $('#<%="pe_ev" + params['queue_name']%>').html('<%= escape_javascript render(:partial => "pending_events_res") %>');
@@ -0,0 +1,20 @@
1
+ %h3 #{params[:queue_name]} pending (#{@pending_count})
2
+
3
+ = render :partial => "pags"
4
+
5
+ = will_paginate @pending
6
+
7
+ %table{:class => "table table-bordered", :style => "font-size: 8pt;"}
8
+ %tr
9
+ %td{:width => "10%"} EvId
10
+ %td{:width => "15%"} Insert At
11
+ %td{:width => "20%"} Event Type
12
+ %td Data
13
+ - @pending.each do |event|
14
+ %tr
15
+ %td= event['ev_id']
16
+ %td= Time.parse(event['ev_time']).strftime("%d.%m.%Y %H:%M:%S") rescue '-'
17
+ %td= event['ev_type']
18
+ %td= Pgq::Consumer.coder.load(event['ev_data']).join(",") rescue '-'
19
+
20
+ = will_paginate @pending
@@ -0,0 +1 @@
1
+ $('#<%="ev_#{params['ev_id']}"%>').html('<%= @res %>');
@@ -0,0 +1,8 @@
1
+
2
+ class PgqWeb::Watcher
3
+ class << self
4
+ attr_accessor :databases
5
+ end
6
+
7
+ self.databases = [ ActiveRecord::Base ]
8
+ end
@@ -0,0 +1,32 @@
1
+ require 'will_paginate/view_helpers/link_renderer'
2
+ require 'will_paginate/view_helpers/action_view'
3
+
4
+ module WillPaginate
5
+ module ActionView
6
+ def will_paginate(collection = nil, options = {})
7
+ options[:renderer] ||= BootstrapLinkRenderer
8
+ super.try :html_safe
9
+ end
10
+
11
+ class BootstrapLinkRenderer < LinkRenderer
12
+ protected
13
+
14
+ def html_container(html)
15
+ tag :div, tag(:ul, html), container_attributes
16
+ end
17
+
18
+ def page_number(page)
19
+ tag :li, link(page, page, :rel => rel_value(page)), :class => ('active' if page == current_page)
20
+ end
21
+
22
+ def previous_or_next_page(page, text, classname)
23
+ tag :li, link(text, page || '#'), :class => [classname[0..3], classname, ('disabled' unless page)].join(' ')
24
+ end
25
+
26
+ def gap
27
+ tag :li, link(super, '#'), :class => 'disabled'
28
+ end
29
+
30
+ end
31
+ end
32
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ PgqWeb::Engine.routes.draw do
2
+ match '/' => 'pgq#index'
3
+ match '/:action(/:id)' => "pgq#"
4
+ end
@@ -0,0 +1,5 @@
1
+ module PgqWeb
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace PgqWeb
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module PgqWeb
2
+ VERSION = "0.0.1"
3
+ end
data/lib/pgq_web.rb ADDED
@@ -0,0 +1,4 @@
1
+ require "pgq_web/engine"
2
+
3
+ module PgqWeb
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :pgq_web do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,261 @@
1
+ == Welcome to Rails
2
+
3
+ Rails is a web-application framework that includes everything needed to create
4
+ database-backed web applications according to the Model-View-Control pattern.
5
+
6
+ This pattern splits the view (also called the presentation) into "dumb"
7
+ templates that are primarily responsible for inserting pre-built data in between
8
+ HTML tags. The model contains the "smart" domain objects (such as Account,
9
+ Product, Person, Post) that holds all the business logic and knows how to
10
+ persist themselves to a database. The controller handles the incoming requests
11
+ (such as Save New Account, Update Product, Show Post) by manipulating the model
12
+ and directing data to the view.
13
+
14
+ In Rails, the model is handled by what's called an object-relational mapping
15
+ layer entitled Active Record. This layer allows you to present the data from
16
+ database rows as objects and embellish these data objects with business logic
17
+ methods. You can read more about Active Record in
18
+ link:files/vendor/rails/activerecord/README.html.
19
+
20
+ The controller and view are handled by the Action Pack, which handles both
21
+ layers by its two parts: Action View and Action Controller. These two layers
22
+ are bundled in a single package due to their heavy interdependence. This is
23
+ unlike the relationship between the Active Record and Action Pack that is much
24
+ more separate. Each of these packages can be used independently outside of
25
+ Rails. You can read more about Action Pack in
26
+ link:files/vendor/rails/actionpack/README.html.
27
+
28
+
29
+ == Getting Started
30
+
31
+ 1. At the command prompt, create a new Rails application:
32
+ <tt>rails new myapp</tt> (where <tt>myapp</tt> is the application name)
33
+
34
+ 2. Change directory to <tt>myapp</tt> and start the web server:
35
+ <tt>cd myapp; rails server</tt> (run with --help for options)
36
+
37
+ 3. Go to http://localhost:3000/ and you'll see:
38
+ "Welcome aboard: You're riding Ruby on Rails!"
39
+
40
+ 4. Follow the guidelines to start developing your application. You can find
41
+ the following resources handy:
42
+
43
+ * The Getting Started Guide: http://guides.rubyonrails.org/getting_started.html
44
+ * Ruby on Rails Tutorial Book: http://www.railstutorial.org/
45
+
46
+
47
+ == Debugging Rails
48
+
49
+ Sometimes your application goes wrong. Fortunately there are a lot of tools that
50
+ will help you debug it and get it back on the rails.
51
+
52
+ First area to check is the application log files. Have "tail -f" commands
53
+ running on the server.log and development.log. Rails will automatically display
54
+ debugging and runtime information to these files. Debugging info will also be
55
+ shown in the browser on requests from 127.0.0.1.
56
+
57
+ You can also log your own messages directly into the log file from your code
58
+ using the Ruby logger class from inside your controllers. Example:
59
+
60
+ class WeblogController < ActionController::Base
61
+ def destroy
62
+ @weblog = Weblog.find(params[:id])
63
+ @weblog.destroy
64
+ logger.info("#{Time.now} Destroyed Weblog ID ##{@weblog.id}!")
65
+ end
66
+ end
67
+
68
+ The result will be a message in your log file along the lines of:
69
+
70
+ Mon Oct 08 14:22:29 +1000 2007 Destroyed Weblog ID #1!
71
+
72
+ More information on how to use the logger is at http://www.ruby-doc.org/core/
73
+
74
+ Also, Ruby documentation can be found at http://www.ruby-lang.org/. There are
75
+ several books available online as well:
76
+
77
+ * Programming Ruby: http://www.ruby-doc.org/docs/ProgrammingRuby/ (Pickaxe)
78
+ * Learn to Program: http://pine.fm/LearnToProgram/ (a beginners guide)
79
+
80
+ These two books will bring you up to speed on the Ruby language and also on
81
+ programming in general.
82
+
83
+
84
+ == Debugger
85
+
86
+ Debugger support is available through the debugger command when you start your
87
+ Mongrel or WEBrick server with --debugger. This means that you can break out of
88
+ execution at any point in the code, investigate and change the model, and then,
89
+ resume execution! You need to install ruby-debug to run the server in debugging
90
+ mode. With gems, use <tt>sudo gem install ruby-debug</tt>. Example:
91
+
92
+ class WeblogController < ActionController::Base
93
+ def index
94
+ @posts = Post.all
95
+ debugger
96
+ end
97
+ end
98
+
99
+ So the controller will accept the action, run the first line, then present you
100
+ with a IRB prompt in the server window. Here you can do things like:
101
+
102
+ >> @posts.inspect
103
+ => "[#<Post:0x14a6be8
104
+ @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>,
105
+ #<Post:0x14a6620
106
+ @attributes={"title"=>"Rails", "body"=>"Only ten..", "id"=>"2"}>]"
107
+ >> @posts.first.title = "hello from a debugger"
108
+ => "hello from a debugger"
109
+
110
+ ...and even better, you can examine how your runtime objects actually work:
111
+
112
+ >> f = @posts.first
113
+ => #<Post:0x13630c4 @attributes={"title"=>nil, "body"=>nil, "id"=>"1"}>
114
+ >> f.
115
+ Display all 152 possibilities? (y or n)
116
+
117
+ Finally, when you're ready to resume execution, you can enter "cont".
118
+
119
+
120
+ == Console
121
+
122
+ The console is a Ruby shell, which allows you to interact with your
123
+ application's domain model. Here you'll have all parts of the application
124
+ configured, just like it is when the application is running. You can inspect
125
+ domain models, change values, and save to the database. Starting the script
126
+ without arguments will launch it in the development environment.
127
+
128
+ To start the console, run <tt>rails console</tt> from the application
129
+ directory.
130
+
131
+ Options:
132
+
133
+ * Passing the <tt>-s, --sandbox</tt> argument will rollback any modifications
134
+ made to the database.
135
+ * Passing an environment name as an argument will load the corresponding
136
+ environment. Example: <tt>rails console production</tt>.
137
+
138
+ To reload your controllers and models after launching the console run
139
+ <tt>reload!</tt>
140
+
141
+ More information about irb can be found at:
142
+ link:http://www.rubycentral.org/pickaxe/irb.html
143
+
144
+
145
+ == dbconsole
146
+
147
+ You can go to the command line of your database directly through <tt>rails
148
+ dbconsole</tt>. You would be connected to the database with the credentials
149
+ defined in database.yml. Starting the script without arguments will connect you
150
+ to the development database. Passing an argument will connect you to a different
151
+ database, like <tt>rails dbconsole production</tt>. Currently works for MySQL,
152
+ PostgreSQL and SQLite 3.
153
+
154
+ == Description of Contents
155
+
156
+ The default directory structure of a generated Ruby on Rails application:
157
+
158
+ |-- app
159
+ | |-- assets
160
+ | |-- images
161
+ | |-- javascripts
162
+ | `-- stylesheets
163
+ | |-- controllers
164
+ | |-- helpers
165
+ | |-- mailers
166
+ | |-- models
167
+ | `-- views
168
+ | `-- layouts
169
+ |-- config
170
+ | |-- environments
171
+ | |-- initializers
172
+ | `-- locales
173
+ |-- db
174
+ |-- doc
175
+ |-- lib
176
+ | `-- tasks
177
+ |-- log
178
+ |-- public
179
+ |-- script
180
+ |-- test
181
+ | |-- fixtures
182
+ | |-- functional
183
+ | |-- integration
184
+ | |-- performance
185
+ | `-- unit
186
+ |-- tmp
187
+ | |-- cache
188
+ | |-- pids
189
+ | |-- sessions
190
+ | `-- sockets
191
+ `-- vendor
192
+ |-- assets
193
+ `-- stylesheets
194
+ `-- plugins
195
+
196
+ app
197
+ Holds all the code that's specific to this particular application.
198
+
199
+ app/assets
200
+ Contains subdirectories for images, stylesheets, and JavaScript files.
201
+
202
+ app/controllers
203
+ Holds controllers that should be named like weblogs_controller.rb for
204
+ automated URL mapping. All controllers should descend from
205
+ ApplicationController which itself descends from ActionController::Base.
206
+
207
+ app/models
208
+ Holds models that should be named like post.rb. Models descend from
209
+ ActiveRecord::Base by default.
210
+
211
+ app/views
212
+ Holds the template files for the view that should be named like
213
+ weblogs/index.html.erb for the WeblogsController#index action. All views use
214
+ eRuby syntax by default.
215
+
216
+ app/views/layouts
217
+ Holds the template files for layouts to be used with views. This models the
218
+ common header/footer method of wrapping views. In your views, define a layout
219
+ using the <tt>layout :default</tt> and create a file named default.html.erb.
220
+ Inside default.html.erb, call <% yield %> to render the view using this
221
+ layout.
222
+
223
+ app/helpers
224
+ Holds view helpers that should be named like weblogs_helper.rb. These are
225
+ generated for you automatically when using generators for controllers.
226
+ Helpers can be used to wrap functionality for your views into methods.
227
+
228
+ config
229
+ Configuration files for the Rails environment, the routing map, the database,
230
+ and other dependencies.
231
+
232
+ db
233
+ Contains the database schema in schema.rb. db/migrate contains all the
234
+ sequence of Migrations for your schema.
235
+
236
+ doc
237
+ This directory is where your application documentation will be stored when
238
+ generated using <tt>rake doc:app</tt>
239
+
240
+ lib
241
+ Application specific libraries. Basically, any kind of custom code that
242
+ doesn't belong under controllers, models, or helpers. This directory is in
243
+ the load path.
244
+
245
+ public
246
+ The directory available for the web server. Also contains the dispatchers and the
247
+ default HTML files. This should be set as the DOCUMENT_ROOT of your web
248
+ server.
249
+
250
+ script
251
+ Helper scripts for automation and generation.
252
+
253
+ test
254
+ Unit and functional tests along with fixtures. When using the rails generate
255
+ command, template test files will be generated for you and placed in this
256
+ directory.
257
+
258
+ vendor
259
+ External libraries that the application depends on. Also includes the plugins
260
+ subdirectory. If the app has frozen rails, those gems also go here, under
261
+ vendor/rails/. This directory is in the load path.
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env rake
2
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
3
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
4
+
5
+ require File.expand_path('../config/application', __FILE__)
6
+
7
+ Dummy::Application.load_tasks
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,3 @@
1
+ class ApplicationController < ActionController::Base
2
+ protect_from_forgery
3
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,4 @@
1
+ class Base2 < ActiveRecord::Base
2
+ self.abstract_class = true
3
+ establish_connection "#{Rails.env || 'development'}2"
4
+ end
@@ -0,0 +1,10 @@
1
+ class PgqCleanup < Pgq::Consumer
2
+
3
+ # to insert event: PgqCleanup.my_event(1, 2, 3)
4
+
5
+ # async execute
6
+ def my_event(a, b, c)
7
+ logger.info "async call my_event with #{[a, b, c].inspect}"
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ class PgqHistory < Pgq::Consumer
2
+
3
+ # to insert event: PgqHistory.my_event(1, 2, 3)
4
+
5
+ # async execute
6
+ def my_event(a, b, c)
7
+ logger.info "async call my_event with #{[a, b, c].inspect}"
8
+ end
9
+
10
+ end
@@ -0,0 +1,11 @@
1
+ class PgqIssues < Consumer2
2
+
3
+ # to insert event: PgqIssue.my_event(1, 2, 3)
4
+
5
+ # async execute
6
+ def my_event(a, b, c)
7
+ sleep 0.2
8
+ logger.info "async call my_event with #{[a, b, c].inspect}"
9
+ end
10
+
11
+ end
@@ -0,0 +1,10 @@
1
+ class PgqPackFile < Pgq::Consumer
2
+
3
+ # to insert event: PgqPackFile.my_event(1, 2, 3)
4
+
5
+ # async execute
6
+ def my_event(a, b, c)
7
+ logger.info "async call my_event with #{[a, b, c].inspect}"
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ class PgqPlaces < Pgq::Consumer
2
+
3
+ # to insert event: PgqPlaces.my_event(1, 2, 3)
4
+
5
+ # async execute
6
+ def my_event(a, b, c)
7
+ logger.info "async call my_event with #{[a, b, c].inspect}"
8
+ end
9
+
10
+ end