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 +4 -4
- data/README.md +23 -9
- data/Rakefile +1 -0
- data/lib/generators/sidejobs/{install_generator.rb → install/install_generator.rb} +3 -3
- data/lib/generators/sidejobs/{templates/configuration.rb → install/templates/initializer.rb} +0 -0
- data/lib/generators/sidejobs/{templates → install/templates}/migration.rb +1 -5
- data/lib/sidejobs/job.rb +5 -1
- data/lib/sidejobs/railtie.rb +1 -1
- data/lib/sidejobs/version.rb +3 -1
- data/lib/tasks/sidejobs.rake +5 -0
- data/test/dummy/bin/bundle +1 -0
- data/test/dummy/bin/rails +1 -0
- data/test/dummy/bin/rake +1 -0
- data/test/dummy/bin/setup +2 -1
- data/test/dummy/config/database.yml.travis +2 -11
- data/test/dummy/config/environments/development.rb +1 -6
- data/test/dummy/config/environments/test.rb +2 -2
- data/test/dummy/config/initializers/mime_types.rb +1 -1
- data/test/dummy/config/secrets.yml +3 -3
- data/test/dummy/db/migrate/20161022211612_create_sidejobs.rb +1 -5
- data/test/dummy/log/sidejobs.log +115 -1782
- data/test/dummy/log/test.log +393 -14469
- data/test/dummy/public/404.html +57 -63
- data/test/dummy/public/422.html +57 -63
- data/test/dummy/public/500.html +56 -62
- data/test/generator_test.rb +3 -4
- metadata +6 -10
- data/test/dummy/db/schema.rb +0 -37
- data/test/dummy/log/development.log +0 -228
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 149454f6f7e3af76c6730bacd7116b802ebaf558
|
4
|
+
data.tar.gz: 72f425083d2c8c139cb0aaa532c01582a6c1a161
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
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
|
-
|
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
|
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
@@ -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
|
11
|
-
copy_file '
|
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
|
data/lib/generators/sidejobs/{templates/configuration.rb → install/templates/initializer.rb}
RENAMED
File without changes
|
@@ -1,11 +1,7 @@
|
|
1
1
|
class CreateSidejobs < ActiveRecord::Migration
|
2
2
|
def change
|
3
3
|
create_table :sidejobs do |t|
|
4
|
-
|
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
|
-
|
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
|
data/lib/sidejobs/railtie.rb
CHANGED
data/lib/sidejobs/version.rb
CHANGED
data/lib/tasks/sidejobs.rake
CHANGED
@@ -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
|
data/test/dummy/bin/bundle
CHANGED
data/test/dummy/bin/rails
CHANGED
data/test/dummy/bin/rake
CHANGED
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
|
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
|
-
|
12
|
-
database:
|
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
|
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
|
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
|
43
|
+
# Set queue adapter.
|
44
44
|
config.active_job.queue_adapter = :sidejobs
|
45
45
|
end
|
@@ -11,12 +11,12 @@
|
|
11
11
|
# if you're sharing your code publicly.
|
12
12
|
|
13
13
|
development:
|
14
|
-
secret_key_base:
|
14
|
+
secret_key_base: 2c1c8d4cbaa726b21aa6483b7d556125f4897508e2b94f8b3ddaec675168382c9b3b6eb5a9359d2fade03f539c16ac1ef905891c2410f2fd00b83b76c1666feb
|
15
15
|
|
16
16
|
test:
|
17
|
-
secret_key_base:
|
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[
|
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
|
-
|
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
|