tanga_que_extensions 0.0.26 → 0.0.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jobs/watch_child_jobs.rb +6 -1
- data/lib/wait_for_child_jobs.rb +4 -1
- data/test/test_child_jobs.rb +14 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f614ac8cdd834509af12ae7c9021e3211555340e
|
4
|
+
data.tar.gz: b2a20d5f534086c6581ddb0be634c0c983614fc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a45896e61025aa10231b324a13117badfed2c4f71d3b23e7ead183fde937b3ffcc1ee3eab806b0a4d7b27040ed0c8898186561216153b9d5110eed708829f13
|
7
|
+
data.tar.gz: f45a72e77b829b8f8c4da950e3299bfbc41192d569440f47555b036d39b8f652874de4d96c02cdbf5bb1eff16a8dbfffac3d418d5cf6109a2e6bd4f8af6de4c5
|
@@ -3,10 +3,15 @@ module Jobs
|
|
3
3
|
def run(options)
|
4
4
|
unless QueJob.where(parent_job_id: options[:job_id]).count > 0
|
5
5
|
QueJobStatus.where(job_id: options[:job_id]).update_all(finished_at: Time.now, status: 'finished')
|
6
|
+
|
7
|
+
if options[:on_finished_job_class].present?
|
8
|
+
options[:on_finished_job_class].constantize.enqueue(job_id: options[:job_id]);
|
9
|
+
end
|
10
|
+
|
6
11
|
return
|
7
12
|
end
|
8
13
|
|
9
|
-
self.class.enqueue(options.merge(run_at: Time.current +
|
14
|
+
self.class.enqueue(options.merge(run_at: Time.current + 5.second))
|
10
15
|
end
|
11
16
|
end
|
12
17
|
end
|
data/lib/wait_for_child_jobs.rb
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
module Que::WaitForChildJobs
|
2
2
|
def record_job_finished
|
3
3
|
job_scope.update_all(status: 'waiting-for-child-jobs')
|
4
|
-
Jobs::WatchChildJobs.enqueue(
|
4
|
+
Jobs::WatchChildJobs.enqueue(
|
5
|
+
job_id: job_id,
|
6
|
+
on_finished_job_class: (defined? on_finished_job_class) ? on_finished_job_class : nil
|
7
|
+
)
|
5
8
|
end
|
6
9
|
end
|
data/test/test_child_jobs.rb
CHANGED
@@ -12,6 +12,14 @@ Que.connection = ActiveRecord
|
|
12
12
|
|
13
13
|
ActiveRecord::Base.logger = Logger.new($stdout)
|
14
14
|
|
15
|
+
class OnFinish < Que::Job
|
16
|
+
prepend Que::RecordJobStatus
|
17
|
+
|
18
|
+
def run(args)
|
19
|
+
puts args.inspect
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
15
23
|
class Child < Que::ChildJob
|
16
24
|
prepend Que::RecordJobStatus
|
17
25
|
prepend Que::RecordJobStatusToParentJob
|
@@ -31,6 +39,10 @@ class Parent < Que::Job
|
|
31
39
|
Child.enqueue(i: i, parent_job_id: job_id)
|
32
40
|
end
|
33
41
|
end
|
42
|
+
|
43
|
+
def on_finished_job_class
|
44
|
+
OnFinish.to_s
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
QueJob.delete_all
|
@@ -40,3 +52,5 @@ Que.mode = :async
|
|
40
52
|
|
41
53
|
Parent.enqueue
|
42
54
|
gets
|
55
|
+
Que.mode = :none
|
56
|
+
binding.pry
|