jobly 0.4.6 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/jobly/api.rb +2 -2
- data/lib/jobly/commands/run.rb +3 -3
- data/lib/jobly/job.rb +20 -15
- data/lib/jobly/job_extensions/isolation.rb +27 -0
- data/lib/jobly/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b656a4bd0004a23f887711cc2c1d9813bb25a83549687d7ec84cd87878bf0aa6
|
4
|
+
data.tar.gz: 4044fda2137858843f2e951cee9a8a8a1e50fda6a217f8d40f700ab6e86b8da8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7d67e9bb33ab98774b0493f2785291934a999de99ac50b606e25e44c96ebe1fdab2251bf274f63892a6e60ea060075dd17ac156ce4b22dcbccf72e88ae9b493a
|
7
|
+
data.tar.gz: 04d847fb7b1874317d5ef050178926628f1fceffd32a5ac1006e8d45291ebd8ddbe750773fbe9969beae511f751c98c89e83520f6e13c4511941b14a95f0dd63
|
data/lib/jobly/api.rb
CHANGED
data/lib/jobly/commands/run.rb
CHANGED
@@ -22,14 +22,14 @@ module Jobly
|
|
22
22
|
if args['--later']
|
23
23
|
say "Scheduling !txtgrn!#{job_class}"
|
24
24
|
if params.empty?
|
25
|
-
job_class.
|
25
|
+
job_class.run_later
|
26
26
|
else
|
27
|
-
job_class.
|
27
|
+
job_class.run_later params
|
28
28
|
end
|
29
29
|
|
30
30
|
else
|
31
31
|
say "Running !txtgrn!#{job_class}"
|
32
|
-
job_class.
|
32
|
+
job_class.run params
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
data/lib/jobly/job.rb
CHANGED
@@ -5,6 +5,7 @@ module Jobly
|
|
5
5
|
include JobExtensions::OptionAccessors
|
6
6
|
include JobExtensions::Actions
|
7
7
|
include JobExtensions::Solo
|
8
|
+
include JobExtensions::Isolation
|
8
9
|
|
9
10
|
# Helpers must come after Sidekiq::Worker since they both bring logger
|
10
11
|
# and our logger is the king of loggers
|
@@ -17,35 +18,39 @@ module Jobly
|
|
17
18
|
attr_reader :params
|
18
19
|
|
19
20
|
class << self
|
20
|
-
# Allow
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# Allow calling a job with `JobName.execute` instead of
|
25
|
-
# `JobName.new.execute`, for consistency.
|
26
|
-
def execute(*args)
|
27
|
-
new.execute *args
|
21
|
+
# Allow running a job with `JobName.run`
|
22
|
+
def run(params = {})
|
23
|
+
new.perform params
|
28
24
|
end
|
29
25
|
|
30
|
-
# Allow
|
31
|
-
|
32
|
-
|
33
|
-
new.perform *args
|
26
|
+
# Allow running a job asynchronously with `JobName.run_later`
|
27
|
+
def run_later(params = {})
|
28
|
+
perform_async params
|
34
29
|
end
|
35
|
-
|
36
30
|
end
|
37
31
|
|
38
32
|
# This is the method sidekiq will call. We capture this call and convert
|
39
33
|
# the hash argument which was converted to array on sidekiq's side, back
|
40
34
|
# to a hash so we can forward to the job's `execute` method, which may
|
41
35
|
# implement keyword args.
|
42
|
-
|
36
|
+
# If the job was marked as isolated, we will run it in its own temporary
|
37
|
+
# directory.
|
38
|
+
def perform(params = {})
|
39
|
+
if isolated?
|
40
|
+
in_isolation { perform! params }
|
41
|
+
else
|
42
|
+
perform! params
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Run the job with its filters and actions.
|
47
|
+
def perform!(params = {})
|
43
48
|
@params = params
|
44
49
|
run_to_completion if run_before_filter
|
45
50
|
end
|
46
51
|
|
47
52
|
# Inheriting classes must implement this method only.
|
48
|
-
def execute(params={})
|
53
|
+
def execute(params = {})
|
49
54
|
raise NotImplementedError
|
50
55
|
end
|
51
56
|
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Jobly
|
2
|
+
module JobExtensions
|
3
|
+
module Isolation
|
4
|
+
def self.included(base)
|
5
|
+
base.extend ClassMethods
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
attr_reader :isolate
|
10
|
+
|
11
|
+
def isolated(enabled = true)
|
12
|
+
@isolate = enabled
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def in_isolation
|
17
|
+
Dir.mktmpdir 'jobly-' do |dir|
|
18
|
+
Dir.chdir(dir) { yield }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def isolated?
|
23
|
+
self.class.isolate
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/jobly/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jobly
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Danny Ben Shitrit
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: http
|
@@ -272,6 +272,7 @@ files:
|
|
272
272
|
- lib/jobly/helpers/slack.rb
|
273
273
|
- lib/jobly/job.rb
|
274
274
|
- lib/jobly/job_extensions/actions.rb
|
275
|
+
- lib/jobly/job_extensions/isolation.rb
|
275
276
|
- lib/jobly/job_extensions/option_accessors.rb
|
276
277
|
- lib/jobly/job_extensions/solo.rb
|
277
278
|
- lib/jobly/jobs.rb
|