sidejobs 0.0.1 → 4.0.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13c5ef1d9d233c888d758b942da10a980b46d75d
4
- data.tar.gz: 7efac020aee70f251f7ce5d2682899d078e5a2bb
3
+ metadata.gz: 149454f6f7e3af76c6730bacd7116b802ebaf558
4
+ data.tar.gz: 72f425083d2c8c139cb0aaa532c01582a6c1a161
5
5
  SHA512:
6
- metadata.gz: d50fda67d9726aa4bf94aabba4defcb04d7ec19e45b23060ab16e3b345b0e615183b10430d8ec68af4c240cc6af34c7f5087cbf7a3bee0f9ecdc72d7609931e8
7
- data.tar.gz: d7a52d18d78bcfe948ab762399bcab78592209042ca9b0749398db947ac82100e76fd8813fc856a196bc0ff84ae5407ec5333dc508d57f404baae17ae5b71a4b
6
+ metadata.gz: b56514cc63f9d71506a7478e8f78a9c1cdaa002e3cf9f42ca43acde04aba81a9c64eb5e2c13f3e84c201a0e5f47835099d11ab25f1ba109c3809455c2475ab2d
7
+ data.tar.gz: b7d5da12f866ef3a038b82a19bf18bc2cda862e12710819ed2d8d5e32aa7d9bc855148751d3554fd1dfd1f1b8b270485060b3159053466cba0fad3e253d7d2c7
data/README.md CHANGED
@@ -7,6 +7,14 @@
7
7
 
8
8
  Versatile async database based jobs for rails.
9
9
 
10
+ ## Why
11
+
12
+ I did this gem to:
13
+
14
+ - Avoid the need to install another admin interface.
15
+ - Simplify the job api by having close integration to rails.
16
+ - Using sql instead of redis to never lose jobs.
17
+
10
18
  ## Install
11
19
 
12
20
  Put this line in your Gemfile:
@@ -23,10 +31,10 @@ $ bundle
23
31
 
24
32
  Generate the sidejobs configuration and migration file:
25
33
  ```
26
- bundle exec rails g sidejobs:install
34
+ $ bundle exec rails g sidejobs:install
27
35
  ```
28
36
 
29
- The default configuration options are:
37
+ Set the global settings:
30
38
  ```ruby
31
39
  Sidejobs.configure do |config|
32
40
  config.max_attempts = 3
@@ -37,7 +45,7 @@ end
37
45
 
38
46
  Run the migration to create the sidejobs table:
39
47
  ```
40
- bundle exec rake db:migrate
48
+ $ bundle exec rake db:migrate
41
49
  ```
42
50
 
43
51
  Assign the sidejobs adapter to the environments:
@@ -49,12 +57,18 @@ end
49
57
 
50
58
  ## Usage
51
59
 
52
- Start the daemon using the rake task:
60
+ ### Daemon
61
+
62
+ To control the daemon, use the rake tasks:
53
63
  ```
54
- bundle exec rake sidejobs:start
64
+ $ bundle exec rake sidejobs:start
65
+ $ bundle exec rake sidejobs:stop
66
+ $ bundle exec rake sidejobs:restart
55
67
  ```
56
68
 
57
- Now you can deliver mails using deliver_later:
69
+ ### Queue
70
+
71
+ You can deliver mails using deliver_later:
58
72
  ```ruby
59
73
  UserMailer.invite('someone@mail.com').deliver_later
60
74
  ```
@@ -64,13 +78,13 @@ Or perform jobs using perform_later:
64
78
  SendNewsletterJob.perform_later
65
79
  ```
66
80
 
67
- Management is done programtically using Sidejobs::Job model:
81
+ ### Management
82
+
83
+ No admin interface, all is done using Sidejobs::Job model:
68
84
  ```ruby
69
85
  Sidejobs::Job.failing.where('attempts > ?', 3).destroy_all
70
86
  ```
71
87
 
72
- NOTE: Is better to do it this way to have the freedom to integrate the code anyway you want.
73
-
74
88
  ## Credits
75
89
 
76
90
  This gem is maintained and funded by [mmontossi](https://github.com/mmontossi).
data/Rakefile CHANGED
@@ -13,6 +13,7 @@ Rake::TestTask.new(:test) do |t|
13
13
  t.libs << 'test'
14
14
  t.pattern = 'test/**/*_test.rb'
15
15
  t.verbose = false
16
+ t.warning = false
16
17
  end
17
18
 
18
19
  task default: :test
@@ -2,13 +2,13 @@ require 'rails/generators'
2
2
 
3
3
  module Sidejobs
4
4
  module Generators
5
- class InstallGenerator < Rails::Generators::Base
5
+ class InstallGenerator < ::Rails::Generators::Base
6
6
  include Rails::Generators::Migration
7
7
 
8
8
  source_root File.expand_path('../templates', __FILE__)
9
9
 
10
- def create_configuration_file
11
- copy_file 'configuration.rb', 'config/initializers/sidejobs.rb'
10
+ def create_initializer_file
11
+ copy_file 'initializer.rb', 'config/initializers/sidejobs.rb'
12
12
  end
13
13
 
14
14
  def create_migration_file
@@ -1,11 +1,7 @@
1
1
  class CreateSidejobs < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :sidejobs do |t|
4
- if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
5
- t.jsonb :data
6
- else
7
- t.string :data
8
- end
4
+ t.jsonb :data
9
5
  t.string :queue
10
6
  t.string :status, default: 'pending'
11
7
  t.integer :priority, default: 0
data/lib/sidejobs/job.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Sidejobs
2
2
  class Job < ActiveRecord::Base
3
- self.table_name = 'sidejobs'
3
+
4
4
  STATUS = %w(pending processing failing complete)
5
5
 
6
6
  STATUS.each do |name|
@@ -17,5 +17,9 @@ module Sidejobs
17
17
  validates_inclusion_of :status, within: STATUS
18
18
  validates_numericality_of :priority, :attempts, only_integer: true
19
19
 
20
+ def self.table_name
21
+ 'sidejobs'
22
+ end
23
+
20
24
  end
21
25
  end
@@ -1,7 +1,7 @@
1
1
  module Sidejobs
2
2
  class Railtie < Rails::Railtie
3
3
 
4
- initializer :sidejobs do
4
+ initializer 'sidejobs.extensions' do
5
5
  ::ActiveJob::QueueAdapters.include(
6
6
  Sidejobs::Extensions::ActiveJob::QueueAdapters
7
7
  )
@@ -1,3 +1,5 @@
1
1
  module Sidejobs
2
- VERSION = '0.0.1'
2
+
3
+ VERSION = '4.0.0.0'
4
+
3
5
  end
@@ -1,10 +1,15 @@
1
1
  namespace :sidejobs do
2
+ desc 'Start daemon.'
2
3
  task start: :environment do
3
4
  Sidejobs.daemon.start
4
5
  end
6
+
7
+ desc 'Stop daemon.'
5
8
  task stop: :environment do
6
9
  Sidejobs.daemon.stop
7
10
  end
11
+
12
+ desc 'Restart daemon.'
8
13
  task restart: :environment do
9
14
  Sidejobs.daemon.restart
10
15
  end
@@ -1,3 +1,4 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
4
  load Gem.bin_path('bundler', 'bundle')
data/test/dummy/bin/rails CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  APP_PATH = File.expand_path('../../config/application', __FILE__)
3
4
  require_relative '../config/boot'
4
5
  require 'rails/commands'
data/test/dummy/bin/rake CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require_relative '../config/boot'
3
4
  require 'rake'
4
5
  Rake.application.run
data/test/dummy/bin/setup CHANGED
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+
2
3
  require 'pathname'
3
4
 
4
5
  # path to your application root.
@@ -8,7 +9,7 @@ Dir.chdir APP_ROOT do
8
9
  # This script is a starting point to setup your application.
9
10
  # Add necessary setup steps to this file:
10
11
 
11
- puts "== Installing dependencies =="
12
+ puts '== Installing dependencies =='
12
13
  system 'gem install bundler --conservative'
13
14
  system 'bundle check || bundle install'
14
15
 
@@ -1,12 +1,3 @@
1
- mysql: &mysql
2
- adapter: <%= 'jdbc' if RUBY_ENGINE == 'jruby' %>mysql<%= '2' if RUBY_ENGINE != 'jruby' %>
3
-
4
- postgres: &postgres
5
- adapter: <%= 'jdbc' if RUBY_ENGINE == 'jruby' %>postgresql
6
-
7
- sqlite: &sqlite
8
- adapter: <%= 'jdbc' if RUBY_ENGINE == 'jruby' %>sqlite3
9
-
10
1
  test:
11
- <<: *<%= ENV['DB'] %>
12
- database: <%= ENV['DB'] == 'sqlite' ? 'db/travis.sqlite3' : 'travis' %>
2
+ adapter: <%= 'jdbc' if RUBY_ENGINE == 'jruby' %>postgresql
3
+ database: travis
@@ -39,11 +39,6 @@ Rails.application.configure do
39
39
  # Raises error for missing translations
40
40
  # config.action_view.raise_on_missing_translations = true
41
41
 
42
- # Set activejob adapter.
42
+ # Set queue adapter.
43
43
  config.active_job.queue_adapter = :sidejobs
44
-
45
- # Tell Action Mailer not to deliver emails to the real world.
46
- # The :test delivery method accumulates sent emails in the
47
- # ActionMailer::Base.deliveries array.
48
- config.action_mailer.delivery_method = :test
49
44
  end
@@ -13,7 +13,7 @@ Rails.application.configure do
13
13
  config.eager_load = false
14
14
 
15
15
  # Configure static file server for tests with Cache-Control for performance.
16
- config.serve_static_files = true
16
+ config.serve_static_files = true
17
17
  config.static_cache_control = 'public, max-age=3600'
18
18
 
19
19
  # Show full error reports and disable caching.
@@ -40,6 +40,6 @@ Rails.application.configure do
40
40
  # Raises error for missing translations
41
41
  # config.action_view.raise_on_missing_translations = true
42
42
 
43
- # Set activejob adapter.
43
+ # Set queue adapter.
44
44
  config.active_job.queue_adapter = :sidejobs
45
45
  end
@@ -1,4 +1,4 @@
1
1
  # Be sure to restart your server when you modify this file.
2
2
 
3
3
  # Add new mime types for use in respond_to blocks:
4
- # Mime::Type.register "text/richtext", :rtf
4
+ # Mime::Type.register 'text/richtext', :rtf
@@ -11,12 +11,12 @@
11
11
  # if you're sharing your code publicly.
12
12
 
13
13
  development:
14
- secret_key_base: ed24994bc56ed26e162af469d5bcc0b7e9bd3ce6aad6613e2415d07c459264c337ecde0a8a346137f6647ddbb8a19bbe4c3ca4428a08e2656b098b6c2131ef15
14
+ secret_key_base: 2c1c8d4cbaa726b21aa6483b7d556125f4897508e2b94f8b3ddaec675168382c9b3b6eb5a9359d2fade03f539c16ac1ef905891c2410f2fd00b83b76c1666feb
15
15
 
16
16
  test:
17
- secret_key_base: 68a2537b2e96696ba28be32feb40fcbd35d7783afbcedf2139f054b1d79ffc31c1f26a9bf9a916cb67f191a6c69a3660878d825cc888c2598a15ab779df6f10c
17
+ secret_key_base: 9dd531171128e7c3d11dd2c5c18c84ba43d29b677043002634a6f4d58bf2687a283b7b6dc6af741d63c3824f11fa1f858010d7c2509a932023f2ece0d3bfe6cf
18
18
 
19
19
  # Do not keep production secrets in the repository,
20
20
  # instead read values from the environment.
21
21
  production:
22
- secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
22
+ secret_key_base: <%= ENV['SECRET_KEY_BASE'] %>
@@ -1,11 +1,7 @@
1
1
  class CreateSidejobs < ActiveRecord::Migration
2
2
  def change
3
3
  create_table :sidejobs do |t|
4
- if ActiveRecord::Base.connection_config[:adapter] == 'postgresql'
5
- t.jsonb :data
6
- else
7
- t.string :data
8
- end
4
+ t.jsonb :data
9
5
  t.string :queue
10
6
  t.string :status, default: 'pending'
11
7
  t.integer :priority, default: 0