active_worker 0.50.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. data/.document +5 -0
  2. data/.rvmrc +1 -0
  3. data/Gemfile +22 -0
  4. data/Gemfile.lock +77 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +19 -0
  7. data/Rakefile +46 -0
  8. data/VERSION +1 -0
  9. data/active_worker.gemspec +108 -0
  10. data/lib/active_worker.rb +29 -0
  11. data/lib/active_worker/behavior/acts_as_root_object.rb +80 -0
  12. data/lib/active_worker/behavior/can_be_notified.rb +23 -0
  13. data/lib/active_worker/behavior/create_from_error.rb +21 -0
  14. data/lib/active_worker/behavior/execute_concurrently.rb +142 -0
  15. data/lib/active_worker/behavior/has_modes.rb +44 -0
  16. data/lib/active_worker/behavior/has_root_object.rb +50 -0
  17. data/lib/active_worker/behavior/hashable.rb +79 -0
  18. data/lib/active_worker/configuration.rb +143 -0
  19. data/lib/active_worker/controller.rb +112 -0
  20. data/lib/active_worker/event.rb +68 -0
  21. data/lib/active_worker/expandable.rb +77 -0
  22. data/lib/active_worker/failure_event.rb +16 -0
  23. data/lib/active_worker/finished_event.rb +9 -0
  24. data/lib/active_worker/host_information.rb +13 -0
  25. data/lib/active_worker/job_queue/job_executer.rb +52 -0
  26. data/lib/active_worker/job_queue/queue_manager.rb +46 -0
  27. data/lib/active_worker/job_queue/run_remotely.rb +52 -0
  28. data/lib/active_worker/modes_map.rb +37 -0
  29. data/lib/active_worker/notification_event.rb +9 -0
  30. data/lib/active_worker/parent_event.rb +5 -0
  31. data/lib/active_worker/started_event.rb +10 -0
  32. data/lib/active_worker/templatable.rb +46 -0
  33. data/lib/active_worker/template.rb +41 -0
  34. data/lib/active_worker/termination_event.rb +21 -0
  35. data/test/mongoid.yml +28 -0
  36. data/test/test_acts_as_root_object.rb +123 -0
  37. data/test/test_can_be_notified.rb +44 -0
  38. data/test/test_configuration.rb +281 -0
  39. data/test/test_controller.rb +205 -0
  40. data/test/test_event.rb +75 -0
  41. data/test/test_execute_concurrently.rb +134 -0
  42. data/test/test_expandable.rb +113 -0
  43. data/test/test_failure_event.rb +69 -0
  44. data/test/test_finished_event.rb +35 -0
  45. data/test/test_has_modes.rb +56 -0
  46. data/test/test_helper.rb +120 -0
  47. data/test/test_integration.rb +56 -0
  48. data/test/test_job_executer.rb +65 -0
  49. data/test/test_queue_manager.rb +106 -0
  50. data/test/test_run_remotely.rb +63 -0
  51. data/test/test_started_event.rb +23 -0
  52. data/test/test_templatable.rb +45 -0
  53. data/test/test_template.rb +29 -0
  54. data/test/test_termination_event.rb +28 -0
  55. metadata +201 -0
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm use 1.9.3-p0@active_worker --create
data/Gemfile ADDED
@@ -0,0 +1,22 @@
1
+ source "https://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rdoc", "~> 3.12"
10
+ gem "bundler"
11
+ gem "jeweler", "~> 1.8.3"
12
+ end
13
+
14
+ group :test do
15
+ gem 'mocha', require: false
16
+ gem 'activesupport'
17
+ gem 'test-unit'
18
+ end
19
+
20
+ gem 'mongoid'
21
+ gem 'bson_ext' #, '=1.4.0'
22
+ gem 'resque', :git => "git://github.com/SoftwareWithFriends/resque.git", :branch => "FEATURE_logging_changes"
@@ -0,0 +1,77 @@
1
+ GIT
2
+ remote: git://github.com/SoftwareWithFriends/resque.git
3
+ revision: 2bdbf13e6f50c223cd7c6c8873fb865a77cc9e63
4
+ branch: FEATURE_logging_changes
5
+ specs:
6
+ resque (1.24.1)
7
+ mono_logger (~> 1.0)
8
+ multi_json (~> 1.0)
9
+ redis-namespace (~> 1.2)
10
+ sinatra (>= 0.9.2)
11
+ vegas (~> 0.1.2)
12
+
13
+ GEM
14
+ remote: https://rubygems.org/
15
+ specs:
16
+ activemodel (3.2.6)
17
+ activesupport (= 3.2.6)
18
+ builder (~> 3.0.0)
19
+ activesupport (3.2.6)
20
+ i18n (~> 0.6)
21
+ multi_json (~> 1.0)
22
+ bson (1.6.4)
23
+ bson_ext (1.6.1)
24
+ bson (~> 1.6.1)
25
+ builder (3.0.4)
26
+ git (1.2.5)
27
+ i18n (0.6.0)
28
+ jeweler (1.8.3)
29
+ bundler (~> 1.0)
30
+ git (>= 1.2.5)
31
+ rake
32
+ rdoc
33
+ json (1.6.6)
34
+ metaclass (0.0.1)
35
+ mocha (0.10.5)
36
+ metaclass (~> 0.0.1)
37
+ mongoid (3.0.21)
38
+ activemodel (~> 3.1)
39
+ moped (~> 1.2)
40
+ origin (~> 1.0)
41
+ tzinfo (~> 0.3.22)
42
+ mono_logger (1.0.1)
43
+ moped (1.4.0)
44
+ multi_json (1.6.1)
45
+ origin (1.0.11)
46
+ rack (1.5.2)
47
+ rack-protection (1.5.0)
48
+ rack
49
+ rake (0.9.2.2)
50
+ rdoc (3.12)
51
+ json (~> 1.4)
52
+ redis (3.0.4)
53
+ redis-namespace (1.3.0)
54
+ redis (~> 3.0.0)
55
+ sinatra (1.4.2)
56
+ rack (~> 1.5, >= 1.5.2)
57
+ rack-protection (~> 1.4)
58
+ tilt (~> 1.3, >= 1.3.4)
59
+ test-unit (2.5.4)
60
+ tilt (1.4.1)
61
+ tzinfo (0.3.35)
62
+ vegas (0.1.11)
63
+ rack (>= 1.0.0)
64
+
65
+ PLATFORMS
66
+ ruby
67
+
68
+ DEPENDENCIES
69
+ activesupport
70
+ bson_ext
71
+ bundler
72
+ jeweler (~> 1.8.3)
73
+ mocha
74
+ mongoid
75
+ rdoc (~> 3.12)
76
+ resque!
77
+ test-unit
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 perf
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.
@@ -0,0 +1,19 @@
1
+ = active_worker
2
+
3
+ Frame work for running jobs.
4
+
5
+ == Contributing to active_worker
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
9
+ * Fork the project.
10
+ * Start a feature/bugfix branch.
11
+ * Commit and push until you are happy with your contribution.
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2012 perf. See LICENSE.txt for
18
+ further details.
19
+
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "active_worker"
18
+ gem.homepage = "http://github.com/ryanmcgarvey/active_worker"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Framework for making class distributable on a queueing system.}
21
+ gem.description = %Q{Uses a Configuration/Controller pattern to allow easy implementation and organziation of multi-tier distributed workloads.}
22
+ gem.email = "perf@skarven.net"
23
+ gem.authors = ["perf"]
24
+ # dependencies defined in Gemfile
25
+ end
26
+ Jeweler::RubygemsDotOrgTasks.new
27
+
28
+ require 'rake/testtask'
29
+ Rake::TestTask.new(:test) do |test|
30
+ test.libs << 'lib' << 'test'
31
+ test.pattern = 'test/**/test_*.rb'
32
+ test.verbose = true
33
+ end
34
+
35
+
36
+ task :default => :test
37
+
38
+ require 'rdoc/task'
39
+ Rake::RDocTask.new do |rdoc|
40
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
41
+
42
+ rdoc.rdoc_dir = 'rdoc'
43
+ rdoc.title = "active_worker #{version}"
44
+ rdoc.rdoc_files.include('README*')
45
+ rdoc.rdoc_files.include('lib/**/*.rb')
46
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.50.0
@@ -0,0 +1,108 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = "active_worker"
8
+ s.version = "0.50.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["perf"]
12
+ s.date = "2013-07-01"
13
+ s.description = "Uses a Configuration/Controller pattern to allow easy implementation and organziation of multi-tier distributed workloads."
14
+ s.email = "perf@skarven.net"
15
+ s.extra_rdoc_files = [
16
+ "LICENSE.txt",
17
+ "README.rdoc"
18
+ ]
19
+ s.files = [
20
+ ".document",
21
+ ".rvmrc",
22
+ "Gemfile",
23
+ "Gemfile.lock",
24
+ "LICENSE.txt",
25
+ "README.rdoc",
26
+ "Rakefile",
27
+ "VERSION",
28
+ "active_worker.gemspec",
29
+ "lib/active_worker.rb",
30
+ "lib/active_worker/behavior/acts_as_root_object.rb",
31
+ "lib/active_worker/behavior/can_be_notified.rb",
32
+ "lib/active_worker/behavior/create_from_error.rb",
33
+ "lib/active_worker/behavior/execute_concurrently.rb",
34
+ "lib/active_worker/behavior/has_modes.rb",
35
+ "lib/active_worker/behavior/has_root_object.rb",
36
+ "lib/active_worker/behavior/hashable.rb",
37
+ "lib/active_worker/configuration.rb",
38
+ "lib/active_worker/controller.rb",
39
+ "lib/active_worker/event.rb",
40
+ "lib/active_worker/expandable.rb",
41
+ "lib/active_worker/failure_event.rb",
42
+ "lib/active_worker/finished_event.rb",
43
+ "lib/active_worker/host_information.rb",
44
+ "lib/active_worker/job_queue/job_executer.rb",
45
+ "lib/active_worker/job_queue/queue_manager.rb",
46
+ "lib/active_worker/job_queue/run_remotely.rb",
47
+ "lib/active_worker/modes_map.rb",
48
+ "lib/active_worker/notification_event.rb",
49
+ "lib/active_worker/parent_event.rb",
50
+ "lib/active_worker/started_event.rb",
51
+ "lib/active_worker/templatable.rb",
52
+ "lib/active_worker/template.rb",
53
+ "lib/active_worker/termination_event.rb",
54
+ "test/mongoid.yml",
55
+ "test/test_acts_as_root_object.rb",
56
+ "test/test_can_be_notified.rb",
57
+ "test/test_configuration.rb",
58
+ "test/test_controller.rb",
59
+ "test/test_event.rb",
60
+ "test/test_execute_concurrently.rb",
61
+ "test/test_expandable.rb",
62
+ "test/test_failure_event.rb",
63
+ "test/test_finished_event.rb",
64
+ "test/test_has_modes.rb",
65
+ "test/test_helper.rb",
66
+ "test/test_integration.rb",
67
+ "test/test_job_executer.rb",
68
+ "test/test_queue_manager.rb",
69
+ "test/test_run_remotely.rb",
70
+ "test/test_started_event.rb",
71
+ "test/test_templatable.rb",
72
+ "test/test_template.rb",
73
+ "test/test_termination_event.rb"
74
+ ]
75
+ s.homepage = "http://github.com/ryanmcgarvey/active_worker"
76
+ s.licenses = ["MIT"]
77
+ s.require_paths = ["lib"]
78
+ s.rubygems_version = "1.8.24"
79
+ s.summary = "Framework for making class distributable on a queueing system."
80
+
81
+ if s.respond_to? :specification_version then
82
+ s.specification_version = 3
83
+
84
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
85
+ s.add_runtime_dependency(%q<mongoid>, [">= 0"])
86
+ s.add_runtime_dependency(%q<bson_ext>, [">= 0"])
87
+ s.add_runtime_dependency(%q<resque>, [">= 0"])
88
+ s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
89
+ s.add_development_dependency(%q<bundler>, [">= 0"])
90
+ s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
91
+ else
92
+ s.add_dependency(%q<mongoid>, [">= 0"])
93
+ s.add_dependency(%q<bson_ext>, [">= 0"])
94
+ s.add_dependency(%q<resque>, [">= 0"])
95
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
96
+ s.add_dependency(%q<bundler>, [">= 0"])
97
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
98
+ end
99
+ else
100
+ s.add_dependency(%q<mongoid>, [">= 0"])
101
+ s.add_dependency(%q<bson_ext>, [">= 0"])
102
+ s.add_dependency(%q<resque>, [">= 0"])
103
+ s.add_dependency(%q<rdoc>, ["~> 3.12"])
104
+ s.add_dependency(%q<bundler>, [">= 0"])
105
+ s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
106
+ end
107
+ end
108
+
@@ -0,0 +1,29 @@
1
+ require 'mongoid'
2
+ require 'resque'
3
+
4
+ require 'active_worker/job_queue/run_remotely'
5
+ require 'active_worker/job_queue/job_executer'
6
+
7
+ require 'active_worker/behavior/acts_as_root_object'
8
+ require 'active_worker/behavior/execute_concurrently'
9
+ require 'active_worker/behavior/has_root_object'
10
+ require 'active_worker/behavior/hashable'
11
+ require 'active_worker/behavior/create_from_error'
12
+
13
+ require 'active_worker/event'
14
+ require 'active_worker/notification_event'
15
+ require 'active_worker/finished_event'
16
+ require 'active_worker/failure_event'
17
+ require 'active_worker/parent_event'
18
+
19
+ require 'active_worker/configuration'
20
+ require 'active_worker/controller'
21
+
22
+ require 'active_worker/host_information'
23
+ require 'active_worker/templatable'
24
+
25
+ #Load anything else that is missing.
26
+ Dir.glob("#{File.dirname(__FILE__)}/active_worker/**/*.rb").each do |file|
27
+ require file
28
+ end
29
+
@@ -0,0 +1,80 @@
1
+ module ActiveWorker
2
+ module Behavior
3
+ module ActsAsRootObject
4
+
5
+ module ClassExtensions
6
+ def acts_as_root_for(relation, class_name)
7
+ has_many relation, :dependent => :delete,
8
+ :class_name => class_name,
9
+ :as => :root_object,
10
+ :autosave => true
11
+ end
12
+ end
13
+
14
+ def self.included(base)
15
+ base.extend(ClassExtensions)
16
+ base.send(:include, Mongoid::Timestamps)
17
+ base.field :root_object_finished, :type => Boolean, :default => false
18
+ base.field :finished_at, :type => Time
19
+ base.field :flags, :type => Hash, :default => {}
20
+ base.before_save :set_flags
21
+ base.acts_as_root_for :configurations, "ActiveWorker::Configuration"
22
+ base.acts_as_root_for :events, "ActiveWorker::Event"
23
+ end
24
+
25
+ def duration
26
+ if completed? && finished_at
27
+ return finished_at - created_at
28
+ end
29
+
30
+ if completed? && !finished_at
31
+ return 0
32
+ end
33
+
34
+ Time.now - created_at
35
+ end
36
+
37
+ def completed?
38
+ self.root_object_finished
39
+ end
40
+
41
+ def child_started
42
+ self.root_object_finished = false
43
+ end
44
+
45
+ def child_finished
46
+ self.root_object_finished = calculate_completed
47
+ end
48
+
49
+ def calculate_completed
50
+ immediate_child_configurations.each do |config|
51
+ return false unless config.completed?
52
+ end
53
+ self.finished_at = Time.now
54
+ true
55
+ end
56
+
57
+ def renderable_configurations
58
+ immediate_child_configurations.select { |c| c.renderable }
59
+ end
60
+
61
+ def immediate_child_configurations
62
+ configurations.where(parent_configuration_id: nil)
63
+ end
64
+
65
+ def renderable_configuration_hashes
66
+ @renderable_configurations_hash ||= ActiveWorker::Configuration.get_renderable_hash_by_root_object(self)
67
+ end
68
+
69
+ def all_configuration_hashes
70
+ @renderable_configurations_hash ||= ActiveWorker::Configuration.get_as_flat_hash_by_root_object(self)
71
+ end
72
+
73
+ def set_flags
74
+ immediate_child_configurations.each do |config|
75
+ config.update_attributes(:flags => flags)
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,23 @@
1
+ module ActiveWorker
2
+ module Behavior
3
+ module CanBeNotified
4
+
5
+ module ClassMethods
6
+ SLEEP_DURATION = 5
7
+
8
+ def process_notifications(initial_configuration, thread_expanded_configurations)
9
+ if initial_configuration.wait_for_notifications
10
+ sleep SLEEP_DURATION until initial_configuration.notified?
11
+ thread_expanded_configurations.map(&:notify)
12
+ end
13
+ end
14
+ end
15
+
16
+ def self.included(base)
17
+ base.extend(ClassMethods)
18
+ base.after_thread_launch :process_notifications
19
+ end
20
+
21
+ end
22
+ end
23
+ end