sidejobs 5.1.0 → 5.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/generators/sidejobs/install/templates/migration.rb +5 -5
- data/lib/sidejobs/job.rb +7 -8
- data/lib/sidejobs/processor.rb +3 -3
- data/lib/sidejobs/queue.rb +1 -1
- data/lib/sidejobs/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '0911dac77f937d3227914732dd6120de78360b0a'
|
4
|
+
data.tar.gz: 4f65f14fd0c5bc20d02953f165afb4548c47d187
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ba869b6c3c50497e2e6e1901dce7447383c578680a029107eb59e7d1c3b078016c04ea13aeb1d30712c8ae82b167efc50117705b11accab5b8929f3b63a14e98
|
7
|
+
data.tar.gz: 4345486f1017beea0c53f1323ea5106bfb09295379072c1f42c9b9c64707d84335690af91c9676f82b896650cc9909505421c3338627e809d49e1c4b6669f2db
|
@@ -1,21 +1,21 @@
|
|
1
|
-
class CreateSidejobs < ActiveRecord::Migration
|
1
|
+
class CreateSidejobs < ActiveRecord::Migration[5.1]
|
2
2
|
def change
|
3
3
|
create_table :sidejobs do |t|
|
4
4
|
t.jsonb :data
|
5
5
|
t.string :queue
|
6
|
-
t.string :
|
6
|
+
t.string :state, default: 'pending'
|
7
7
|
t.integer :priority, default: 0
|
8
8
|
t.integer :attempts, default: 0
|
9
9
|
t.text :error
|
10
|
-
t.datetime :failed_at
|
11
|
-
t.datetime :completed_at
|
12
10
|
t.datetime :processed_at
|
13
11
|
t.datetime :scheduled_at
|
14
12
|
|
15
13
|
t.timestamps null: false
|
16
14
|
end
|
17
15
|
|
18
|
-
add_index :sidejobs,
|
16
|
+
add_index :sidejobs, :state
|
17
|
+
add_index :sidejobs, :scheduled_at
|
18
|
+
add_index :sidejobs, :attempts
|
19
19
|
add_index :sidejobs, :priority
|
20
20
|
end
|
21
21
|
end
|
data/lib/sidejobs/job.rb
CHANGED
@@ -1,20 +1,19 @@
|
|
1
1
|
module Sidejobs
|
2
2
|
class Job < ActiveRecord::Base
|
3
3
|
|
4
|
-
|
4
|
+
STATES = %w(pending processing failing complete)
|
5
5
|
|
6
|
-
|
7
|
-
scope name, -> { where(
|
6
|
+
STATES.each do |name|
|
7
|
+
scope name, -> { where(state: name) }
|
8
8
|
define_method "#{name}?" do
|
9
|
-
|
9
|
+
state == name
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
validates_presence_of :queue, :data, :
|
14
|
-
validates_presence_of :error,
|
15
|
-
validates_presence_of :completed_at, if: :complete?
|
13
|
+
validates_presence_of :queue, :data, :state
|
14
|
+
validates_presence_of :error, if: :failing?
|
16
15
|
validates_presence_of :processed_at, if: :processing?
|
17
|
-
validates_inclusion_of :
|
16
|
+
validates_inclusion_of :state, within: STATES
|
18
17
|
validates_numericality_of :priority, :attempts, only_integer: true
|
19
18
|
|
20
19
|
def self.table_name
|
data/lib/sidejobs/processor.rb
CHANGED
@@ -4,12 +4,12 @@ module Sidejobs
|
|
4
4
|
|
5
5
|
def process
|
6
6
|
Sidejobs.queue.fetch.each do |job|
|
7
|
-
job.update
|
7
|
+
job.update state: 'processing', processed_at: Time.zone.now, attempts: job.attempts+1
|
8
8
|
begin
|
9
9
|
ActiveJob::Base.execute job.data
|
10
|
-
job.update
|
10
|
+
job.update state: 'complete'
|
11
11
|
rescue => exception
|
12
|
-
job.update
|
12
|
+
job.update state: 'failing', error: exception.message
|
13
13
|
end
|
14
14
|
end
|
15
15
|
end
|
data/lib/sidejobs/queue.rb
CHANGED
data/lib/sidejobs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sidejobs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 5.1.
|
4
|
+
version: 5.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- mmontossi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-11-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|