tanga_que_extensions 0.0.18 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c78c9eff18224f0e67bcd590d61853fa71878255
4
- data.tar.gz: c29b06e03dd3fdd039c9f5be1fb366ce929b7331
3
+ metadata.gz: 9aae367072232fd5da235b0aa176823cbb84fed0
4
+ data.tar.gz: 33b0388eca8e5cbd44cbb4eddabe35667507f7ca
5
5
  SHA512:
6
- metadata.gz: 9efa163c9bc22da4ce42d3c1771fca510194cddd55a8b20cce42e091c71e08bd0fdf9a9227f5c9ad5ab97c921a1642c9513ad39171daf63a63a845011a86ff58
7
- data.tar.gz: 47f38d7cbb66477e3d70419eda7e2a7b9e97ae9e4e6d0d402f02964533db618ef93a33c664a816c0108a94d764b32404c859d405b168cfedcd0ea54b3130a650
6
+ metadata.gz: 154e6b003b0b5497f4fa656eb12a548adf51fd3ac4c20e4cd72045ac6a4394f653b25bd406dd29f9f42978e538a91614063fe88ec5887be2405f85e015568063
7
+ data.tar.gz: 8b577e258ffa815885c61bc1dcc192ad1a828f9e7026ff6defd6727ee40306f7d5ab2e57aa8605e429dcba5df939373b626ecfcddfd5ff8d3bbe0bb443e7e9c9
data/lib/child_job.rb ADDED
@@ -0,0 +1,12 @@
1
+ module Que::ChildJob
2
+ def enqueue(*args)
3
+ Que.transaction do
4
+ job_data = super
5
+
6
+ parent_job_id = args.first[:parent_job_id] rescue nil
7
+ if parent_job_id.present?
8
+ QueJob.where(job_id: job_data.attrs['job_id']).update_all(parent_job_id: parent_job_id)
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,12 @@
1
+ module Jobs
2
+ class WatchChildJobs < Que::Job
3
+ def run(options)
4
+ unless QueJob.where(parent_job_id: options[:job_id]).count > 0
5
+ QueJobStatus.where(job_id: options[:job_id]).update_all(finished_at: Time.now, status: 'finished')
6
+ return
7
+ end
8
+
9
+ self.class.enqueue(options.merge(run_at: Time.current + 1.second))
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Que::RecordJobStatusToParentJob
2
+ def parent_job_id
3
+ @attrs['args'].first['parent_job_id'] || 0
4
+ rescue
5
+ 0
6
+ end
7
+
8
+ def update_job_data(job_data)
9
+ super if defined?(super)
10
+
11
+ parent_job_scope.find_each do |parent_job|
12
+ parent_job.with_lock do
13
+ parent_job.job_data = [] unless parent_job.job_data.kind_of?(Array)
14
+ parent_job.job_data << job_data
15
+ parent_job.save!
16
+ end
17
+ end
18
+ end
19
+
20
+ def parent_job_scope
21
+ QueJobStatus.where(job_id: parent_job_id)
22
+ end
23
+ end
@@ -10,3 +10,7 @@ require_relative 'que_job'
10
10
  require_relative 'que_job_status'
11
11
  require_relative 'set_application_name_when_job_runs'
12
12
  require_relative 'prevent_duplicates'
13
+ require_relative 'wait_for_child_jobs'
14
+ require_relative 'record_job_status_to_parent_job'
15
+ require_relative 'jobs/watch_child_jobs'
16
+ require_relative 'child_job'
@@ -0,0 +1,6 @@
1
+ module Que::WaitForChildJobs
2
+ def record_job_finished
3
+ job_scope.update_all(status: 'waiting-for-child-jobs')
4
+ Jobs::WatchChildJobs.enqueue(job_id: job_id)
5
+ end
6
+ end
@@ -0,0 +1,43 @@
1
+ require 'active_support'
2
+ require 'active_support/core_ext'
3
+ require 'json'
4
+ require 'logger'
5
+ require 'active_record'
6
+ require_relative '../lib/tanga_que_extensions'
7
+
8
+ require 'pry'
9
+
10
+ ActiveRecord::Base.establish_connection 'postgres://localhost/channel_advisor_dev'
11
+ Que.connection = ActiveRecord
12
+
13
+ ActiveRecord::Base.logger = Logger.new($stdout)
14
+
15
+ class Child < Que::Job
16
+ prepend Que::ChildJob
17
+ prepend Que::RecordJobStatus
18
+ prepend Que::RecordJobStatusToParentJob
19
+
20
+ def run(args)
21
+ sleep(args[:i])
22
+ update_job_data(args)
23
+ end
24
+ end
25
+
26
+ class Parent < Que::Job
27
+ prepend Que::RecordJobStatus
28
+ prepend Que::WaitForChildJobs
29
+
30
+ def run(args)
31
+ 5.times do |i|
32
+ Child.enqueue(i: i, parent_job_id: job_id)
33
+ end
34
+ end
35
+ end
36
+
37
+ QueJob.delete_all
38
+ QueJobStatus.delete_all
39
+ Que.logger = Logger.new(STDOUT)
40
+ Que.mode = :async
41
+
42
+ Parent.enqueue
43
+ gets
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tanga_que_extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.18
4
+ version: 0.0.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joe Van Dyk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-30 00:00:00.000000000 Z
11
+ date: 2017-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: que
@@ -88,6 +88,8 @@ extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
90
  - lib/background_job_logger.rb
91
+ - lib/child_job.rb
92
+ - lib/jobs/watch_child_jobs.rb
91
93
  - lib/memory_info.rb
92
94
  - lib/notify_on_failures.rb
93
95
  - lib/periodic_job.rb
@@ -95,9 +97,12 @@ files:
95
97
  - lib/que_job.rb
96
98
  - lib/que_job_status.rb
97
99
  - lib/record_job_status.rb
100
+ - lib/record_job_status_to_parent_job.rb
98
101
  - lib/set_application_name_when_job_runs.rb
99
102
  - lib/tanga_que_extensions.rb
103
+ - lib/wait_for_child_jobs.rb
100
104
  - test/test.rb
105
+ - test/test_child_jobs.rb
101
106
  homepage: https://www.tanga.com
102
107
  licenses: []
103
108
  metadata: {}
@@ -117,9 +122,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
117
122
  version: '0'
118
123
  requirements: []
119
124
  rubyforge_project:
120
- rubygems_version: 2.5.1
125
+ rubygems_version: 2.4.5.1
121
126
  signing_key:
122
127
  specification_version: 4
123
128
  summary: job scheduling stuff for tanga
124
129
  test_files:
130
+ - test/test_child_jobs.rb
125
131
  - test/test.rb