burden 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,3 @@
1
1
  module BurdenWeb
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
data/lib/burden/config.rb CHANGED
@@ -1,12 +1,15 @@
1
1
  module Burden
2
2
  class Config
3
- attr_accessor :storage, # Storage backend (ActiveRecord, Mongoid, MongoMapper)
4
- :ignored_tasks, # Do not log this tasks (eg. environment task)
5
- :on_success, # Success callback (expected to be a Proc)
6
- :on_failure # Failure callback (expected to be a Proc)
3
+ attr_accessor :storage, # Storage backend (ActiveRecord, Mongoid, MongoMapper)
4
+ :storage_config, # Config needed to initialize storage
5
+ :log_file, # Log file
6
+ :ignored_tasks, # Do not log this tasks (eg. environment task)
7
+ :on_success, # Success callback (expected to be a Proc)
8
+ :on_failure # Failure callback (expected to be a Proc)
7
9
 
8
10
  def initialize
9
11
  @storage = :active_record
12
+ @log_file = 'tmp/rake.log'
10
13
  @ignored_tasks = [/environment/]
11
14
  end
12
15
 
@@ -10,32 +10,27 @@ module Burden
10
10
  end
11
11
 
12
12
  def save
13
- if defined?(Rails) && Rails.respond_to?(:application) && Rails.application.present?
14
- # FIXME: Dirty stuff
15
- conf = Rails.configuration.database_configuration[Rails.env]
16
- ActiveRecord::Base.establish_connection(conf)
13
+ # FIXME
14
+ # if Burden.storage.ready?
15
+ # Burden.storage.runs.create(name: name, success: success, execution_time: execution_time, timestamp: timestamp)
16
+ # end
17
17
 
18
- begin
19
- Burden.runs.create(name: name, success: success, execution_time: execution_time, timestamp: timestamp)
20
- rescue
21
- log_to_stdout(:failed)
22
- end
23
- else
24
- log_to_stdout(:no_rails)
18
+ File.open(Burden.config.log_file, 'a') do |f|
19
+ f.write(log_message)
20
+ f.close
25
21
  end
26
22
  end
27
23
 
28
- def log_to_stdout(reason = :no_rails)
29
- puts
30
- puts "------------------------------------------------------------"
31
- case reason
32
- when :no_rails
33
- puts "Rails environment is not loaded. Sending output to STDOUT"
34
- when :failed
35
- puts "Failed to persist this run. Sending output to STDOUT"
36
- end
37
- puts "Task #{name} #{success ? 'finished successfully' : 'failed'}"
38
- puts "Execution time: #{execution_time.round(4)}"
24
+ private
25
+
26
+ def log_message
27
+ <<-TEXT
28
+ Timestamp: #{timestamp}
29
+ Task: #{name}
30
+ Execution #{success ? 'finished successfully' : 'failed'}
31
+ Execution time: #{execution_time.round(4)}
32
+
33
+ TEXT
39
34
  end
40
35
  end
41
36
  end
@@ -1,18 +1,18 @@
1
1
  module Burden
2
2
  module Storage
3
3
  module Helper
4
- def runs
5
- @storage_class ||= begin
4
+ def storage
5
+ @storage ||= begin
6
6
  case Burden.config.storage
7
7
  when :active_record, :activerecord
8
- require 'burden/storage/active_record/run'
9
- Burden::Storage::ActiveRecord::Run
8
+ require 'burden/storage_backends/active_record_backend'
9
+ Burden::StorageBackends::ActiveRecordBackend.new(Burden.config.storage_config)
10
10
  when :mongoid
11
- require 'burden/storage/mongoid/run'
12
- Burden::Storage::Mongoid::Run
11
+ require 'burden/storage_backends/mongoid_backend'
12
+ Burden::StorageBackends::MongoidBackend.new(Burden.config.storage_config)
13
13
  when :mongo_mapper, :mongomapper
14
- require 'burden/storage/mongo_mapper/run'
15
- Burden::Storage::MongoMapper::Run
14
+ require 'burden/storage_backends/mongo_mapper_backend'
15
+ Burden::StorageBackends::MongoMapperBackend.new(Burden.config.storage_config)
16
16
  else
17
17
  raise Exception.new("Unknown storage: #{storage}")
18
18
  end
@@ -1,5 +1,5 @@
1
1
  module Burden
2
- module Storage
2
+ module StorageBackends
3
3
  module Abstract
4
4
  class Run
5
5
  attr_accessor :name, :success, :execution_time, :timestamp
@@ -0,0 +1,18 @@
1
+ require 'burden/storage_backends/abstract/run'
2
+
3
+ module Burden
4
+ module StorageBackends
5
+ class AbstractBackend
6
+ def initialize(config)
7
+ end
8
+
9
+ def ready?
10
+ raise NotImplementedError.new('Method #ready? must be overwritten')
11
+ end
12
+
13
+ def runs
14
+ raise NotImplementedError.new('Method #runs must be overwritten')
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,5 +1,5 @@
1
1
  module Burden
2
- module Storage
2
+ module StorageBackends
3
3
  module ActiveRecord
4
4
  class Run < ::ActiveRecord::Base
5
5
  self.table_name = 'burden_runs'
@@ -0,0 +1,27 @@
1
+ require 'active_record'
2
+ require 'burden/storage_backends/active_record/run'
3
+
4
+ module Burden
5
+ module StorageBackends
6
+ class ActiveRecordBackend
7
+ attr_reader :connection_success
8
+
9
+ def initialize(config)
10
+ @connection_success = true
11
+ begin
12
+ ActiveRecord::Base.establish_connection(config)
13
+ rescue => e
14
+ @connection_success = false
15
+ end
16
+ end
17
+
18
+ def ready?
19
+ @connection_success
20
+ end
21
+
22
+ def runs
23
+ Burden::StorageBackends::ActiveRecord::Run
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,5 @@
1
1
  module Burden
2
- module Storage
2
+ module StorageBackends
3
3
  module MongoMapper
4
4
  class Run
5
5
  include ::MongoMapper::Document
@@ -1,5 +1,5 @@
1
1
  module Burden
2
- module Storage
2
+ module StorageBackends
3
3
  module Mongoid
4
4
  class Run
5
5
  include ::Mongoid::Document
@@ -1,3 +1,3 @@
1
1
  module Burden
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -17,7 +17,11 @@ module Burden
17
17
  block.call
18
18
  end
19
19
  end
20
- save_statistics
20
+
21
+ begin
22
+ save_statistics
23
+ rescue => e
24
+ end
21
25
 
22
26
  unless success
23
27
  Burden.config.trigger_failure_callback(name, execution_time, timestamp)
metadata CHANGED
@@ -2,14 +2,14 @@
2
2
  name: burden
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.2
5
+ version: 0.1.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Gregory Eremin
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-10 00:00:00.000000000 Z
12
+ date: 2013-06-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake
@@ -184,10 +184,12 @@ files:
184
184
  - lib/burden/config.rb
185
185
  - lib/burden/statistics.rb
186
186
  - lib/burden/storage.rb
187
- - lib/burden/storage/abstract/run.rb
188
- - lib/burden/storage/active_record/run.rb
189
- - lib/burden/storage/mongo_mapper/run.rb
190
- - lib/burden/storage/mongoid/run.rb
187
+ - lib/burden/storage_backends/abstract/run.rb
188
+ - lib/burden/storage_backends/abstract_backend.rb
189
+ - lib/burden/storage_backends/active_record/run.rb
190
+ - lib/burden/storage_backends/active_record_backend.rb
191
+ - lib/burden/storage_backends/mongo_mapper/run.rb
192
+ - lib/burden/storage_backends/mongoid/run.rb
191
193
  - lib/burden/version.rb
192
194
  - lib/burden/wrapper.rb
193
195
  - lib/rails/generators/burden/install/USAGE