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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b8a8edcc7454410166815e6adf0f105f71d0d741dc9e61b82ca61e7814c6b671
4
- data.tar.gz: 7e87bb039d4dc9f608ebf747f31aa133ec67dc81a794c683fb0840dd3aeb352c
3
+ metadata.gz: b656a4bd0004a23f887711cc2c1d9813bb25a83549687d7ec84cd87878bf0aa6
4
+ data.tar.gz: 4044fda2137858843f2e951cee9a8a8a1e50fda6a217f8d40f700ab6e86b8da8
5
5
  SHA512:
6
- metadata.gz: ae811324a752834c19ffa0bd116ef121c39d7b8bbbff95e2814155b4be3276662e641b268c1b62c247c6672de6f8c1ae11542d9e040f383c47070f0a3fa030d3
7
- data.tar.gz: b682abaf3ac3005861d5546e5650ba51bb0b432c4c896b630d304b02c63fe1efeff2d81712a51351fe89cab301b98d16a910f58adb725a376b31c9dd167b65c3
6
+ metadata.gz: 7d67e9bb33ab98774b0493f2785291934a999de99ac50b606e25e44c96ebe1fdab2251bf274f63892a6e60ea060075dd17ac156ce4b22dcbccf72e88ae9b493a
7
+ data.tar.gz: 04d847fb7b1874317d5ef050178926628f1fceffd32a5ac1006e8d45291ebd8ddbe750773fbe9969beae511f751c98c89e83520f6e13c4511941b14a95f0dd63
data/lib/jobly/api.rb CHANGED
@@ -62,9 +62,9 @@ module Jobly
62
62
 
63
63
  args = args.convert_to_typed
64
64
  if args.empty?
65
- job_class.perform_async
65
+ job_class.run_later
66
66
  else
67
- job_class.perform_async args
67
+ job_class.run_later args
68
68
  end
69
69
 
70
70
  response = {
@@ -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.perform_async
25
+ job_class.run_later
26
26
  else
27
- job_class.perform_async params
27
+ job_class.run_later params
28
28
  end
29
29
 
30
30
  else
31
31
  say "Running !txtgrn!#{job_class}"
32
- job_class.new.perform params
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 inheriting jobs to use `execute_async` instead of
21
- # `perform_async` for consistency with `execute`
22
- alias_method :execute_async, :perform_async
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 calling a job with `JobName.perform` instead of
31
- # `JobName.new.perform`, for consistency.
32
- def perform(*args)
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
- def perform(params={})
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
@@ -1,3 +1,3 @@
1
1
  module Jobly
2
- VERSION = "0.4.6"
2
+ VERSION = "0.5.0"
3
3
  end
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.6
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-01 00:00:00.000000000 Z
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