say_when 0.3.0 → 1.0.0

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 (53) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +13 -4
  3. data/Gemfile +1 -1
  4. data/LICENSE +21 -0
  5. data/README.md +31 -0
  6. data/Rakefile +9 -1
  7. data/lib/generators/say_when/migration/migration_generator.rb +8 -5
  8. data/lib/generators/say_when/migration/templates/migration.rb +11 -8
  9. data/lib/say_when/base_job.rb +2 -0
  10. data/lib/say_when/cron_expression.rb +129 -191
  11. data/lib/say_when/processor/active_messaging.rb +7 -8
  12. data/lib/say_when/processor/base.rb +5 -3
  13. data/lib/say_when/processor/shoryuken.rb +14 -0
  14. data/lib/say_when/processor/simple.rb +2 -0
  15. data/lib/say_when/railtie.rb +9 -0
  16. data/lib/say_when/scheduler.rb +30 -56
  17. data/lib/say_when/storage/active_record/acts.rb +16 -16
  18. data/lib/say_when/storage/active_record/job.rb +17 -24
  19. data/lib/say_when/storage/active_record/job_execution.rb +5 -8
  20. data/lib/say_when/storage/memory/base.rb +3 -1
  21. data/lib/say_when/storage/memory/job.rb +14 -42
  22. data/lib/say_when/tasks.rb +4 -4
  23. data/lib/say_when/triggers/base.rb +4 -3
  24. data/lib/say_when/triggers/cron_strategy.rb +4 -3
  25. data/lib/say_when/triggers/instance_strategy.rb +4 -3
  26. data/lib/say_when/triggers/once_strategy.rb +3 -2
  27. data/lib/say_when/version.rb +3 -1
  28. data/lib/say_when.rb +8 -7
  29. data/lib/tasks/say_when.rake +3 -1
  30. data/say_when.gemspec +25 -19
  31. data/test/active_record_helper.rb +13 -0
  32. data/{spec → test}/db/schema.rb +4 -2
  33. data/{spec/spec_helper.rb → test/minitest_helper.rb} +9 -12
  34. data/test/say_when/cron_expression_spec.rb +74 -0
  35. data/{spec/say_when/processor/active_messaging_spec.rb → test/say_when/processor/active_messaging_test.rb} +16 -13
  36. data/test/say_when/scheduler_test.rb +75 -0
  37. data/test/say_when/storage/active_record/job_test.rb +90 -0
  38. data/test/say_when/storage/memory/job_test.rb +32 -0
  39. data/test/say_when/storage/memory/trigger_test.rb +54 -0
  40. data/test/say_when/triggers/once_strategy_test.rb +23 -0
  41. data/{spec → test}/support/models.rb +5 -3
  42. metadata +166 -153
  43. data/.travis.yml +0 -4
  44. data/generators/say_when_migration/say_when_migration_generator.rb +0 -11
  45. data/generators/say_when_migration/templates/migration.rb +0 -48
  46. data/spec/active_record_spec_helper.rb +0 -11
  47. data/spec/say_when/cron_expression_spec.rb +0 -72
  48. data/spec/say_when/scheduler_spec.rb +0 -76
  49. data/spec/say_when/storage/active_record/job_spec.rb +0 -98
  50. data/spec/say_when/storage/memory/job_spec.rb +0 -45
  51. data/spec/say_when/storage/memory/trigger_spec.rb +0 -54
  52. data/spec/say_when/triggers/once_strategy_spec.rb +0 -22
  53. data/spec/spec.opts +0 -4
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5f6591f3f5206b517960a08efa500fbf3334ff56
4
+ data.tar.gz: 4daa2a598bf163817da9b7987938cc7216ed1f58
5
+ SHA512:
6
+ metadata.gz: 236e345d76fb90f946e90a6d7ed8581bf670823b36965da9110e680f39847656c309e00ecc77d931e113a27648bc29bc37f72223f9a32c94f45a240c64fbff47
7
+ data.tar.gz: 3eb871a517e9e1c7246d7b52957b423c56fc58d47127f1523d2383a6f605314901684ad2a21c70bc3bd620964f6346403d3bf9e10ec70a79a9192a6cb55fda13
data/.gitignore CHANGED
@@ -1,7 +1,16 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /tmp/
9
+ *.bundle
10
+ *.so
11
+ *.o
12
+ *.a
1
13
  *.gem
2
- .bundle
3
- Gemfile.lock
4
- pkg/*
5
14
  *.DS_Store
6
- spec/db/test.db
7
15
  .ruby-version
16
+ test/db/test.db
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in say_when.gemspec
4
4
  gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Andrew Kuklewicz
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # SayWhen
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'say_when'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install say_when
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/say_when/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile CHANGED
@@ -1 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rake/testtask'
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << 'test'
6
+ t.pattern = 'test/**/*_test.rb'
7
+ end
8
+
9
+ task default: :test
@@ -1,18 +1,21 @@
1
+ # encoding: utf-8
2
+
1
3
  require 'rails/generators'
2
4
  require 'rails/generators/migration'
3
- require 'rails/generators/active_record/migration'
5
+ require 'rails/generators/active_record'
4
6
 
5
7
  module SayWhen
6
- class MigrationGenerator < Rails::Generators::Base
8
+ class MigrationGenerator < ActiveRecord::Generators::Base
7
9
 
8
10
  include Rails::Generators::Migration
9
11
  extend ActiveRecord::Generators::Migration
10
12
 
11
13
  source_root File.expand_path('../templates', __FILE__)
12
14
 
13
- def manifest
14
- migration_template 'migration.rb', 'db/migrate/create_say_when_tables'
15
+ argument :name, type: :string, default: 'random_name'
16
+
17
+ def manifest
18
+ migration_template 'migration.rb', 'db/migrate/create_say_when_tables.rb'
15
19
  end
16
-
17
20
  end
18
21
  end
@@ -1,9 +1,10 @@
1
+ # encoding: utf-8
2
+
1
3
  class CreateSayWhenTables < ActiveRecord::Migration
2
-
4
+
3
5
  def self.up
4
6
 
5
7
  create_table :say_when_jobs, :force => true do |t|
6
-
7
8
  t.string :group
8
9
  t.string :name
9
10
 
@@ -25,9 +26,12 @@ class CreateSayWhenTables < ActiveRecord::Migration
25
26
  t.string :scheduled_type
26
27
  t.integer :scheduled_id
27
28
 
28
- t.timestamps
29
+ t.timestamps null: false
29
30
  end
30
31
 
32
+ add_index :say_when_jobs, [:next_fire_at, :status]
33
+ add_index :say_when_jobs, [:scheduled_type, :scheduled_id]
34
+
31
35
  create_table :say_when_job_executions, :force => true do |t|
32
36
  t.integer :job_id
33
37
  t.string :status
@@ -35,14 +39,13 @@ class CreateSayWhenTables < ActiveRecord::Migration
35
39
  t.datetime :start_at
36
40
  t.datetime :end_at
37
41
  end
38
-
39
- add_index :say_when_jobs, :status
40
- add_index :say_when_jobs, :next_fire_at
42
+
43
+ add_index :say_when_job_executions, :job_id
44
+ add_index :say_when_job_executions, [:status, :start_at, :end_at]
41
45
  end
42
-
46
+
43
47
  def self.down
44
48
  drop_table :say_when_job_executions
45
49
  drop_table :say_when_jobs
46
50
  end
47
-
48
51
  end
@@ -1,3 +1,5 @@
1
+ # encoding: utf-8
2
+
1
3
  module SayWhen
2
4
  module BaseJob
3
5