tanga_que_extensions 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/background_job_logger.rb +30 -0
- data/lib/job.rb +6 -0
- data/lib/memory_info.rb +9 -0
- data/lib/notify_on_failures.rb +5 -0
- data/lib/periodic_job.rb +38 -0
- data/lib/record_job_status.rb +36 -0
- data/lib/tanga_que_extensions.rb +7 -0
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aa8f04e9cac8d8598a161af08d8d811c8a28a494
|
4
|
+
data.tar.gz: cf99fbfbe31e7755c51288d54bfb03fdec426e4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a1aa40c78a817a290cbb25067c48213ec80eaceb0ccb32121bf5deabb41e737f8bf20350c696bc8c7361b1c981f04b075aaa4bff608580c9969980f47188ea
|
7
|
+
data.tar.gz: 38e544c730883315262454b6d92cf31026bf9abda02cf0a7e7a3ec10ae728f5d84a5610ea46c61f161aff443253ea37afa2ffb6ee6471a2cae51a4bc0766931c
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Que
|
2
|
+
module BackgroundJobLogger
|
3
|
+
def _run(*)
|
4
|
+
start_time = Time.current
|
5
|
+
start_memory = Que::MemoryInfo.rss
|
6
|
+
|
7
|
+
super
|
8
|
+
|
9
|
+
end_time = Time.current
|
10
|
+
total_run_time = end_time - start_time
|
11
|
+
current_memory = Que::MemoryInfo.rss
|
12
|
+
memory_taken = current_memory - start_memory
|
13
|
+
|
14
|
+
TangaServices.logger.info(
|
15
|
+
service: 'que_jobs',
|
16
|
+
status: 'job_finished',
|
17
|
+
end_time: end_time,
|
18
|
+
total_run_time: total_run_time,
|
19
|
+
job: self.class.name,
|
20
|
+
attrs: attrs,
|
21
|
+
current_memory: current_memory,
|
22
|
+
change_in_memory: memory_taken
|
23
|
+
)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class Job
|
28
|
+
prepend Que::BackgroundJobLogger
|
29
|
+
end
|
30
|
+
end
|
data/lib/job.rb
ADDED
data/lib/memory_info.rb
ADDED
data/lib/periodic_job.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
class Que::PeriodicJob < Que::Job
|
2
|
+
INTERVAL = 60
|
3
|
+
DELAY = 0
|
4
|
+
attr_reader :start_at, :end_at, :run_again_at, :time_range
|
5
|
+
def _run
|
6
|
+
args = attrs[:args].first || {}
|
7
|
+
|
8
|
+
start_at = args.delete('start_at')
|
9
|
+
end_at = args.delete('end_at')
|
10
|
+
|
11
|
+
if start_at.present? && end_at.present?
|
12
|
+
@start_at = Time.parse(start_at)
|
13
|
+
@end_at = Time.parse(end_at)
|
14
|
+
@run_again_at = @end_at + self.class::INTERVAL
|
15
|
+
else
|
16
|
+
@start_at = Time.current
|
17
|
+
@end_at = @start_at + self.class::INTERVAL
|
18
|
+
@run_again_at = @end_at
|
19
|
+
end
|
20
|
+
|
21
|
+
@time_range = @start_at...@end_at
|
22
|
+
|
23
|
+
super
|
24
|
+
|
25
|
+
args['start_at'] = @end_at
|
26
|
+
args['end_at'] = @run_again_at
|
27
|
+
|
28
|
+
Que::Migrations.transaction do
|
29
|
+
self.class.enqueue(args, run_at: @run_again_at + self.class::DELAY)
|
30
|
+
destroy
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_job
|
35
|
+
@time_range = attrs.delete(:time_range)
|
36
|
+
run(attrs)
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Que::RecordJobStatus
|
2
|
+
def job_id
|
3
|
+
@job_id || 0
|
4
|
+
end
|
5
|
+
|
6
|
+
def run(args={})
|
7
|
+
@job_id = self.attrs['job_id']
|
8
|
+
record_job_started
|
9
|
+
super if defined?(super)
|
10
|
+
record_job_finished
|
11
|
+
rescue => e
|
12
|
+
record_job_failed(e)
|
13
|
+
notify_dev_if_needed(e)
|
14
|
+
end
|
15
|
+
|
16
|
+
def notify_dev_if_needed(e)
|
17
|
+
super if defined?(super)
|
18
|
+
end
|
19
|
+
|
20
|
+
def record_job_failed(e)
|
21
|
+
TangaServices.logger.error(service: 'que_jobs', status: 'error', error: e.to_json)
|
22
|
+
job_scope.update_all(status: 'failed', error: { message: e.message, args: e.as_json })
|
23
|
+
end
|
24
|
+
|
25
|
+
def record_job_started
|
26
|
+
QueJobStatus.create!(job_id: job_id, attrs: attrs, status: 'executing')
|
27
|
+
end
|
28
|
+
|
29
|
+
def record_job_finished
|
30
|
+
job_scope.update_all(finished_at: Time.current, status: 'finished')
|
31
|
+
end
|
32
|
+
|
33
|
+
def job_scope
|
34
|
+
QueJobStatus.where(job_id: job_id)
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tanga_que_extensions
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter van Wesep
|
@@ -31,6 +31,13 @@ executables: []
|
|
31
31
|
extensions: []
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
|
+
- lib/background_job_logger.rb
|
35
|
+
- lib/job.rb
|
36
|
+
- lib/memory_info.rb
|
37
|
+
- lib/notify_on_failures.rb
|
38
|
+
- lib/periodic_job.rb
|
39
|
+
- lib/record_job_status.rb
|
40
|
+
- lib/tanga_que_extensions.rb
|
34
41
|
- test/test.rb
|
35
42
|
homepage: https://www.tanga.com
|
36
43
|
licenses: []
|