plok 0.2.7 → 0.2.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/queued_task.rb +28 -8
- data/db/migrate/20211119095633_add_weight_to_queued_tasks.rb +7 -0
- data/db/migrate/20211119103846_add_attempts_to_queued_tasks.rb +7 -0
- data/db/migrate/20211119123900_add_index_to_queued_tasks_locked.rb +7 -0
- data/db/migrate/20211203103118_add_file_to_logs.rb +7 -0
- data/lib/plok/version.rb +1 -1
- data/spec/factories/queued_tasks.rb +1 -0
- metadata +15 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5592ae83ba835a70d2f5abb54e9c2c3769d5584d3a7e86084771e3a0957ee6f
|
4
|
+
data.tar.gz: 0ee4693d3c86231656c3634dfa0bb8b16ef210d46b02695fa3f64fe15d317365
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e293332494ccbc1d7f42fe8195ee17603c797c555ffac962b1b9330e27255c573fe354c063e82b07ca7d88af7e0c241c22b9b8aefc17e2a7a4ba39b77515ebcc
|
7
|
+
data.tar.gz: 461cc4f1684a9e138b791549320015e76acb4aa29ca149eaa6db96223ae36e23610f0b87e1282e5063a6bda5ba9abfb2aacf44afa50dd6cf4cf365d0ab45fa76
|
data/app/models/queued_task.rb
CHANGED
@@ -10,12 +10,15 @@ class QueuedTask < ActiveRecord::Base
|
|
10
10
|
scope :in_past, -> { where(perform_at: nil).or(where('perform_at <= ?', Time.zone.now)) }
|
11
11
|
scope :in_future, -> { where('perform_at > ?', Time.zone.now) }
|
12
12
|
|
13
|
+
DEFAULT_PRIORITY = 0
|
14
|
+
HIGH_PRIORITY = 10
|
15
|
+
|
13
16
|
def lock!
|
14
|
-
update_attribute
|
17
|
+
update_attribute(:locked, true)
|
15
18
|
end
|
16
19
|
|
17
20
|
def unlock!
|
18
|
-
update_attribute
|
21
|
+
update_attribute(:locked, false)
|
19
22
|
end
|
20
23
|
|
21
24
|
def unlocked?
|
@@ -26,22 +29,36 @@ class QueuedTask < ActiveRecord::Base
|
|
26
29
|
klass.to_s.constantize.new(data).execute!
|
27
30
|
end
|
28
31
|
|
29
|
-
|
30
|
-
|
32
|
+
# TODO: Might be good to use named parameters for data and weight here.
|
33
|
+
# Might be able to use the data var to store weight like the perform_at key.
|
34
|
+
#
|
35
|
+
# TODO: Refactor to a separate class.
|
36
|
+
def self.queue(klass, data, weight = DEFAULT_PRIORITY)
|
37
|
+
task = create!(
|
38
|
+
klass: klass.to_s,
|
39
|
+
weight: weight,
|
40
|
+
attempts: 0,
|
41
|
+
data: data&.except(:perform_at)
|
42
|
+
)
|
43
|
+
|
31
44
|
task.update(perform_at: data[:perform_at]) if data[:perform_at].present?
|
32
45
|
task
|
33
46
|
end
|
34
47
|
|
35
|
-
def self.queue_unless_already_queued(klass, data)
|
36
|
-
task = find_by(klass: klass, data: data)
|
48
|
+
def self.queue_unless_already_queued(klass, data, weight = DEFAULT_PRIORITY)
|
49
|
+
task = find_by(klass: klass, data: data, weight: weight)
|
37
50
|
return task if task.present?
|
38
|
-
self.queue(klass, data)
|
51
|
+
self.queue(klass, data, weight)
|
39
52
|
end
|
40
53
|
|
41
54
|
def dequeue!
|
42
55
|
destroy
|
43
56
|
end
|
44
57
|
|
58
|
+
def increase_attempts!
|
59
|
+
update_column(:attempts, attempts + 1)
|
60
|
+
end
|
61
|
+
|
45
62
|
def process!
|
46
63
|
lock!
|
47
64
|
|
@@ -51,7 +68,10 @@ class QueuedTask < ActiveRecord::Base
|
|
51
68
|
rescue
|
52
69
|
raise
|
53
70
|
ensure
|
54
|
-
|
71
|
+
if persisted?
|
72
|
+
increase_attempts!
|
73
|
+
unlock!
|
74
|
+
end
|
55
75
|
end
|
56
76
|
end
|
57
77
|
|
data/lib/plok/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: plok
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Davy Hellemans
|
8
8
|
- Dave Lens
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2022-04-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -29,16 +29,16 @@ dependencies:
|
|
29
29
|
name: mysql2
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- - "
|
32
|
+
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '0'
|
35
|
-
type: :
|
34
|
+
version: '0.5'
|
35
|
+
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- - "
|
39
|
+
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '0'
|
41
|
+
version: '0.5'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec-rails
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -86,6 +86,10 @@ files:
|
|
86
86
|
- config/routes.rb
|
87
87
|
- db/migrate/20211008130809_create_plok_logs.rb
|
88
88
|
- db/migrate/20211015141837_create_plok_queued_tasks.rb
|
89
|
+
- db/migrate/20211119095633_add_weight_to_queued_tasks.rb
|
90
|
+
- db/migrate/20211119103846_add_attempts_to_queued_tasks.rb
|
91
|
+
- db/migrate/20211119123900_add_index_to_queued_tasks_locked.rb
|
92
|
+
- db/migrate/20211203103118_add_file_to_logs.rb
|
89
93
|
- lib/plok.rb
|
90
94
|
- lib/plok/engine.rb
|
91
95
|
- lib/plok/version.rb
|
@@ -98,7 +102,7 @@ licenses:
|
|
98
102
|
- MIT
|
99
103
|
metadata:
|
100
104
|
allowed_push_host: https://rubygems.org
|
101
|
-
post_install_message:
|
105
|
+
post_install_message:
|
102
106
|
rdoc_options: []
|
103
107
|
require_paths:
|
104
108
|
- lib
|
@@ -113,8 +117,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
117
|
- !ruby/object:Gem::Version
|
114
118
|
version: '0'
|
115
119
|
requirements: []
|
116
|
-
rubygems_version: 3.
|
117
|
-
signing_key:
|
120
|
+
rubygems_version: 3.3.9
|
121
|
+
signing_key:
|
118
122
|
specification_version: 4
|
119
123
|
summary: CMS basics
|
120
124
|
test_files: []
|