threads_pad 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (63) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +35 -0
  4. data/lib/generators/threads_pad/USAGE +8 -0
  5. data/lib/generators/threads_pad/templates/threads_pad_job_log_migration.rb +17 -0
  6. data/lib/generators/threads_pad/templates/threads_pad_job_migration.rb +17 -0
  7. data/lib/generators/threads_pad/threads_pad_generator.rb +9 -0
  8. data/lib/tasks/threads_pad_tasks.rake +4 -0
  9. data/lib/threads_pad/helper.rb +58 -0
  10. data/lib/threads_pad/job_reflection.rb +58 -0
  11. data/lib/threads_pad/job_reflection_log.rb +6 -0
  12. data/lib/threads_pad/save_adapter.rb +17 -0
  13. data/lib/threads_pad/version.rb +3 -0
  14. data/lib/threads_pad.rb +231 -0
  15. data/test/dummy/README.rdoc +28 -0
  16. data/test/dummy/Rakefile +6 -0
  17. data/test/dummy/app/assets/javascripts/application.js +13 -0
  18. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  19. data/test/dummy/app/controllers/application_controller.rb +5 -0
  20. data/test/dummy/app/helpers/application_helper.rb +2 -0
  21. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  22. data/test/dummy/bin/bundle +3 -0
  23. data/test/dummy/bin/rails +4 -0
  24. data/test/dummy/bin/rake +4 -0
  25. data/test/dummy/bin/setup +29 -0
  26. data/test/dummy/config/application.rb +26 -0
  27. data/test/dummy/config/boot.rb +5 -0
  28. data/test/dummy/config/database.yml +29 -0
  29. data/test/dummy/config/environment.rb +5 -0
  30. data/test/dummy/config/environments/development.rb +41 -0
  31. data/test/dummy/config/environments/production.rb +79 -0
  32. data/test/dummy/config/environments/test.rb +42 -0
  33. data/test/dummy/config/initializers/assets.rb +11 -0
  34. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  35. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  36. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  37. data/test/dummy/config/initializers/inflections.rb +16 -0
  38. data/test/dummy/config/initializers/mime_types.rb +4 -0
  39. data/test/dummy/config/initializers/session_store.rb +3 -0
  40. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  41. data/test/dummy/config/locales/en.yml +23 -0
  42. data/test/dummy/config/routes.rb +56 -0
  43. data/test/dummy/config/secrets.yml +22 -0
  44. data/test/dummy/config.ru +4 -0
  45. data/test/dummy/db/migrate/20160229125823_create_threads_pad_jobs.rb +17 -0
  46. data/test/dummy/db/migrate/20160229125824_create_threads_pad_job_logs.rb +17 -0
  47. data/test/dummy/db/schema.rb +45 -0
  48. data/test/dummy/lib/generators/threads_pad/USAGE +8 -0
  49. data/test/dummy/lib/generators/threads_pad/templates/threads_pad_job_log_migration.rb +16 -0
  50. data/test/dummy/lib/generators/threads_pad/templates/threads_pad_job_migration.rb +16 -0
  51. data/test/dummy/lib/generators/threads_pad/threads_pad_generator.rb +9 -0
  52. data/test/dummy/log/RAILS_ENV=test.log +0 -0
  53. data/test/dummy/log/development.log +1265 -0
  54. data/test/dummy/log/test.log +311010 -0
  55. data/test/dummy/public/404.html +67 -0
  56. data/test/dummy/public/422.html +67 -0
  57. data/test/dummy/public/500.html +66 -0
  58. data/test/dummy/public/favicon.ico +0 -0
  59. data/test/dummy/test/lib/generators/threads_pad_generator_test.rb +14 -0
  60. data/test/test_helper.rb +19 -0
  61. data/test/threads_pad_helper_test.rb +66 -0
  62. data/test/threads_pad_test.rb +191 -0
  63. metadata +167 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ce2f3d1befecee43f7c1baaa764eab9628fb224f
4
+ data.tar.gz: d33df326fc381eb3ff132b06471cdcea4573cc70
5
+ SHA512:
6
+ metadata.gz: 240b7f2f1bce875790304b6bb3bada98fc2c4f83c762a4b7f6613936090e8677137a6b4a98330a50c051b11a608884253ccfbb832cfed0f5a53f85c2ac062021
7
+ data.tar.gz: c60dad99eab203aacd794d1302f58db1cea4a88a9ecf4ce1536b8d75619d05e2a6955563526db14196f9deb79b17a854ea4acf79e1d5345e00fa7551dfdfd368
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,35 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'ThreadsPad'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ #t.pattern = 'test/threads_pad_helper_test.rb'
31
+ t.verbose = false
32
+ end
33
+
34
+
35
+ task default: :test
@@ -0,0 +1,8 @@
1
+ Description:
2
+ Explain the generator
3
+
4
+ Example:
5
+ rails generate threads_pad Thing
6
+
7
+ This will create:
8
+ what/will/it/create
@@ -0,0 +1,17 @@
1
+ class CreateThreadsPadJobLogs < ActiveRecord::Migration
2
+ def up
3
+ create_table :threads_pad_job_logs do |t|
4
+ t.integer :job_reflection_id
5
+ t.integer :level
6
+ t.integer :group_id
7
+ t.text :msg
8
+ t.datetime "created_at", null: false
9
+ t.index :job_reflection_id
10
+ end
11
+
12
+ end
13
+ def down
14
+ drop_table :threads_pad_job_logs
15
+
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ class CreateThreadsPadJobs < ActiveRecord::Migration
2
+ def change
3
+ create_table :threads_pad_jobs do |t|
4
+ t.boolean :terminated
5
+ t.string :thread_id
6
+ t.boolean :done
7
+ t.string :result
8
+ t.integer :group_id, :integer
9
+ t.integer :max, :integer
10
+ t.integer :current, :integer
11
+ t.integer :min, :integer
12
+ t.boolean :started
13
+ t.boolean :destroy_on_finish
14
+ t.index :group_id
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ require 'rails/generators/active_record'
2
+
3
+ class ThreadsPadGenerator < ActiveRecord::Generators::Base
4
+ source_root File.expand_path('../templates', __FILE__)
5
+ def generate_migration
6
+ migration_template "threads_pad_job_migration.rb", "db/migrate/create_threads_pad_jobs.rb"
7
+ migration_template "threads_pad_job_log_migration.rb", "db/migrate/create_threads_pad_job_logs.rb"
8
+ end
9
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :threads_pad do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,58 @@
1
+ module ThreadsPad
2
+ module Helper
3
+ def filter_job_logs logs
4
+
5
+ ret = []
6
+ if logs.present?
7
+ logs.sort { |x, y| x[:id] <=> y[:id]}. each do |l|
8
+
9
+ if session.has_key? :thread_pad_log_filter
10
+ unless filter_job_log_exist?(l)
11
+ filter_job_logs_save l
12
+ ret << l
13
+ else
14
+
15
+ end
16
+ else
17
+ filter_job_logs_save l
18
+ ret << l
19
+ end
20
+ end
21
+ end
22
+
23
+ return ret
24
+ end
25
+ private
26
+ def filter_job_logs_save l
27
+ return if l[:id].nil? || l[:group_id].nil?
28
+ ses = session[:thread_pad_log_filter] || {}
29
+ key = l[:group_id]
30
+ key = key.to_s if key.is_a? Fixnum
31
+ val = l[:id]
32
+ ses[key] = val
33
+ session[:thread_pad_log_filter] = ses
34
+
35
+
36
+ end
37
+ def filter_job_log_exist? l
38
+ return true if l[:id].nil? || l[:group_id].nil?
39
+
40
+ ses = session[:thread_pad_log_filter]
41
+ key = l[:group_id]
42
+ key = key.to_s if key.is_a? Fixnum
43
+ val = l[:id]
44
+ #ses.symbolize_keys!
45
+ if ses.has_key?(key)
46
+ ses[key].to_i >= l[:id].to_i
47
+ else
48
+ #puts "session #{ses.inspect}. no key #{key.inspect} "
49
+ false
50
+ end
51
+
52
+
53
+
54
+
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ module ThreadsPad
2
+ class JobReflection < ActiveRecord::Base
3
+ self.table_name = "threads_pad_jobs"
4
+ has_many :job_reflection_logs, dependent: :destroy
5
+
6
+ def initialize job, **options
7
+ @job = job
8
+ @current_iteration = 0
9
+ if options[:iteration_sync]
10
+ @iteration_sync = options[:iteration_sync].to_i
11
+ else
12
+ @iteration_sync = 100
13
+ end
14
+
15
+ @job.job_reflection = self if @job.present?
16
+ super()
17
+ init_attributes
18
+
19
+ end
20
+ def init_attributes
21
+ self.current = 0
22
+ self.max = 100
23
+ self.min = 0
24
+ self.started = false
25
+ self.destroy_on_finish = false
26
+ self.save!
27
+ end
28
+
29
+ def start
30
+ @job.start
31
+ end
32
+ def save_if_needed
33
+ @current_iteration += 1
34
+ if @current_iteration > @iteration_sync
35
+ @current_iteration = 0
36
+ save!
37
+ end
38
+
39
+ end
40
+ def reload_if_needed
41
+ @current_iteration += 1
42
+ if @current_iteration > @iteration_sync
43
+ @current_iteration = 0
44
+ reload
45
+ end
46
+ end
47
+ def thread_alive?
48
+ ret = false
49
+ Thread.list.each do |t|
50
+ ret = true if t.object_id.to_s == self.thread_id
51
+
52
+ end
53
+ ret
54
+
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,6 @@
1
+ module ThreadsPad
2
+ class JobReflectionLog < ActiveRecord::Base
3
+ self.table_name = "threads_pad_job_logs"
4
+ belongs_to :job_reflection
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ module ThreadsPad
2
+ class SaveAdapter
3
+ def before_work job
4
+
5
+ end
6
+ def after_work job
7
+ end
8
+ end
9
+ class LogSaveAdapter < SaveAdapter
10
+ def before_work job
11
+ puts "before_work: #{job.inspect}"
12
+ end
13
+ def after_work job
14
+ puts "after_work: #{job.inspect}"
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ module ThreadsPad
2
+ VERSION = "0.1.7"
3
+ end
@@ -0,0 +1,231 @@
1
+ require 'threads_pad/job_reflection_log'
2
+ require 'threads_pad/job_reflection'
3
+ require 'threads_pad/helper'
4
+
5
+ module ThreadsPad
6
+ class Pad
7
+
8
+ def initialize id=nil, **options
9
+ @options = options || {}
10
+ @list = []
11
+ @grp_id = id
12
+ if id
13
+ @group_id = id
14
+ @list = JobReflection.where('group_id = ?', id).to_a
15
+
16
+ end
17
+
18
+ end
19
+
20
+ def << job
21
+ refl = JobReflection.new job, @options
22
+ if @options[:destroy_on_finish]
23
+ refl.destroy_on_finish = true
24
+ refl.save!
25
+ end
26
+ @list << refl
27
+ end
28
+ def empty?
29
+ @list.count == 0
30
+ end
31
+ def start
32
+ @grp_id = get_group_id
33
+ destroy_old
34
+ @list.each do |jr|
35
+ jr.group_id = @grp_id
36
+ jr.started = true
37
+ jr.save!
38
+ jr.start
39
+ end
40
+ @grp_id
41
+ end
42
+ def wait
43
+ ThreadsPad::Pad.wait @list
44
+ end
45
+ def destroy_all
46
+ ThreadsPad::Pad.destroy_all @list
47
+ end
48
+ def destroy_old
49
+ @list.delete_if do |jr|
50
+ jr.destroy if jr.started && jr.done && !jr.thread_alive?
51
+ end
52
+
53
+ end
54
+ def current
55
+ ThreadsPad::Pad.current @list
56
+
57
+ end
58
+ def done?
59
+ ThreadsPad::Pad.done? @list
60
+ end
61
+ def terminate
62
+ ThreadsPad::Pad.terminate @list
63
+ end
64
+ def logs
65
+ return [] if @grp_id.nil?
66
+ JobReflectionLog.where('group_id = ?', @grp_id)
67
+ end
68
+ def log msg, level=0
69
+ return if @grp_id.nil?
70
+ JobReflectionLog.create! group_id: @grp_id, msg: msg, level: level
71
+
72
+ end
73
+ class << self
74
+
75
+ def << job
76
+ refl = JobReflection.new job
77
+ job.start
78
+ return refl
79
+ end
80
+ def destroy_all list=nil
81
+ JobReflectionLog.destroy_all if list.nil?
82
+ list = JobReflection.all if list.nil?
83
+ list.each do |jr|
84
+ if jr.started && !jr.done && jr.thread_alive?
85
+ jr.destroy_on_finish = true
86
+ jr.save!
87
+ else
88
+ jr.destroy #if jr.done #|| !jr.started
89
+ end
90
+ end
91
+
92
+ end
93
+ def wait list=nil, wait_for_destroy_on_finish=false
94
+ sleep 0.1 # needed to be sure other threads are started
95
+ running = true
96
+ list = JobReflection.all if list.nil?
97
+ while running do
98
+ running = false
99
+ list.each do |jr|
100
+ begin
101
+ jr.reload
102
+ running = running || jr.thread_alive? && !jr.done && jr.started && (wait_for_destroy_on_finish || !jr.destroy_on_finish)
103
+ rescue ActiveRecord::RecordNotFound
104
+ end
105
+ end
106
+ #puts "waiting: #{list.inspect}"
107
+
108
+ sleep 0.3
109
+ end
110
+
111
+ end
112
+ def wait_all list=nil
113
+ self.wait list, true
114
+ end
115
+ def current list=nil
116
+ list = JobReflection.all if list.nil?
117
+ res = 0
118
+
119
+ list.each do |jr|
120
+ res += (jr.current.to_f-jr.min)/(jr.max-jr.min) * 100.0 / list.count
121
+ end
122
+ res.round
123
+ end
124
+ def done? list =nil
125
+ list = JobReflection.all if list.nil?
126
+ res = true
127
+ list.each do |jr|
128
+ res &&= jr.done || !jr.thread_alive?
129
+ end
130
+ res
131
+ end
132
+ def terminate list=nil
133
+ list = JobReflection.all if list.nil?
134
+ list.each do |jr|
135
+ jr.terminated = true
136
+ jr.save!
137
+ end
138
+ end
139
+ def empty?
140
+ JobReflection.count == 0
141
+ end
142
+ end
143
+ private
144
+ def get_group_id
145
+ #(JobReflection.maximum("group_id") || 0) + 1
146
+ id = -1
147
+ begin
148
+ id = Random.rand(0..2**31)
149
+ end until JobReflection.where(group_id: id).length == 0
150
+ id
151
+
152
+ end
153
+
154
+ end
155
+
156
+ class Job
157
+ def job_reflection= value
158
+ @job_reflection = value
159
+ end
160
+ def start
161
+ @thread = Thread.new(&(proc{self.wrapper}))
162
+ end
163
+ def wrapper
164
+
165
+ #ActiveRecord::Base.forbid_implicit_checkout_for_thread!
166
+ ActiveRecord::Base.connection_pool.with_connection do
167
+ begin
168
+ @current = 0.0
169
+ @job_reflection.done = false
170
+ @job_reflection.terminated = false
171
+ @job_reflection.started = true
172
+ @job_reflection.thread_id = @thread.object_id.to_s
173
+ @job_reflection.save!
174
+
175
+
176
+ @job_reflection.result = work
177
+ rescue => e
178
+ puts "ThreadsPad::Job#wrapper: #{e.message} #{e.backtrace.inspect}"
179
+ ensure
180
+ @job_reflection.done = true
181
+ if @job_reflection.destroy_on_finish
182
+ @job_reflection.destroy
183
+ else
184
+ @job_reflection.save!
185
+ end
186
+ end
187
+ end
188
+ ActiveRecord::Base.connection.close
189
+ end
190
+ def work
191
+ end
192
+ def min=value
193
+ @job_reflection.min = value
194
+ @job_reflection.save!
195
+ end
196
+ def min
197
+ @job_reflection.min
198
+ end
199
+ def max
200
+ @job_reflection.max
201
+ end
202
+ def max=value
203
+ @job_reflection.max = value
204
+ @job_reflection.save!
205
+ end
206
+ def current=value
207
+ @current = value
208
+ return if @job_reflection.nil?
209
+ @job_reflection.current = @current
210
+ @job_reflection.save_if_needed
211
+ end
212
+ def current
213
+ @current
214
+ end
215
+
216
+ def terminated?
217
+ return false if @job_reflection.nil?
218
+ @job_reflection.reload_if_needed
219
+ @job_reflection.terminated
220
+ end
221
+ def debug msg
222
+ @job_reflection.job_reflection_logs.create(level: 0, msg: msg, group_id: @job_reflection.group_id) if @job_reflection
223
+ rescue => e
224
+ puts "debug: #{e.message}"
225
+ end
226
+ end
227
+ end
228
+
229
+ ActiveSupport.on_load(:action_view) do
230
+ include ThreadsPad::Helper
231
+ end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
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 any plugin's vendor/assets/javascripts directory 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
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,15 @@
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 any plugin's vendor/assets/stylesheets directory 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 bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,26 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require 'rails/all'
4
+
5
+ Bundler.require(*Rails.groups)
6
+ require "threads_pad"
7
+
8
+ module Dummy
9
+ class Application < Rails::Application
10
+ # Settings in config/environments/* take precedence over those specified here.
11
+ # Application configuration should go into files in config/initializers
12
+ # -- all .rb files in that directory are automatically loaded.
13
+
14
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
15
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
16
+ # config.time_zone = 'Central Time (US & Canada)'
17
+
18
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
19
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
20
+ # config.i18n.default_locale = :de
21
+
22
+ # Do not swallow errors in after_commit/after_rollback callbacks.
23
+ config.active_record.raise_in_transactional_callbacks = true
24
+ end
25
+ end
26
+
@@ -0,0 +1,5 @@
1
+ # Set up gems listed in the Gemfile.
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../../../Gemfile', __FILE__)
3
+
4
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
5
+ $LOAD_PATH.unshift File.expand_path('../../../../lib', __FILE__)