joblin 0.1.1 → 0.1.3

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
  SHA256:
3
- metadata.gz: 279121368956a3b2aadd8e8f7941e4901a5ce2f5b66b6571b44893b9303db121
4
- data.tar.gz: '09d69ee51f5e66187bb53ee919e03f8b41d17c42146579f8b88c4af26b89d170'
3
+ metadata.gz: d79f8417c584523ab669a7e4c4d13df180eaad4c921b915073aec83e2c8b6197
4
+ data.tar.gz: 334c035490eeb2537a8503df28585ef6cf736c25ca8822e82e812c2f0841a443
5
5
  SHA512:
6
- metadata.gz: f6e9a084d5609fa974c07d9a371186ea1f48d5ce62965129717b7027bc8f7b91c55ec08c63d6d338956ae0ab3a1d416cca26ebfd6edc2ad3d4d5c6fcc166a3d9
7
- data.tar.gz: b9712224c67f906d710953034f9132f7d56fe5caad37b33a10a1d69186aee0642fd20998b4d1c5452d5e5e8d92e322bfd1b3fac5ec11ed4c8d575aae3eceba2c
6
+ metadata.gz: 48b1d7e9370ca38d31a1a4f4f17943210cd3203a2e0e0c397be45878c520e2a7c50653147e1feb6596cf17ab32fdbccd681938b13fbcf528d660fb358282444b
7
+ data.tar.gz: 7deceab65a315fb8534db3d436fab18ebf96e1452c4d01887a7c35c4b6e57831a6b96299e86f3d3623e1f4b33cab01b78cf9aed664ed6e989b017c28744654da
@@ -16,7 +16,7 @@ module Joblin
16
16
  end
17
17
 
18
18
  def allow_api_access!(&blk)
19
- include ApiAccess::Mixin unless self < ApiAccess::Mixin
19
+ include Mixin unless self < Mixin
20
20
  @api_access_allowed = true
21
21
  api_access_rules(&blk) if blk
22
22
  end
@@ -28,7 +28,7 @@ module Joblin
28
28
 
29
29
  def find_for_api(id)
30
30
  task = find(id)
31
- raise ActiveRecord::RecordNotFound unless task.class.api_access_allowed?
31
+ raise ActiveRecord::RecordNotFound unless task.api_access_allowed?
32
32
  task
33
33
  end
34
34
 
@@ -42,9 +42,9 @@ module Joblin
42
42
 
43
43
  task_type = self == BackgroundTask ? params[:type].safe_constantize : self
44
44
  raise ActiveRecord::RecordNotFound unless task_type && task_type <= BackgroundTask
45
- raise ActiveRecord::RecordNotFound unless task_type.api_access_allowed?
46
45
 
47
46
  task = task_type.new
47
+ raise ActiveRecord::RecordNotFound unless task.api_access_allowed?
48
48
  rule_sets = task_type.api_access_rules
49
49
 
50
50
  # Apply permitted options
@@ -64,6 +64,8 @@ module Joblin
64
64
  # Apply any additional/hard-coded options
65
65
  task.options.merge!(options)
66
66
 
67
+ raise ActiveRecord::RecordInvalid.new(task) unless task.api_access_allowed?
68
+
67
69
  val_errors = task.api_validate_options
68
70
  raise ActiveRecord::ValidationError.new(val_errors) unless val_errors.empty?
69
71
 
@@ -77,14 +79,20 @@ module Joblin
77
79
  end
78
80
  end
79
81
 
82
+ def api_access_allowed?
83
+ self.class.api_access_allowed?
84
+ end
85
+
80
86
  module Mixin
81
87
  extend ActiveSupport::Concern
82
88
 
83
89
  included do
84
- if defined?(BackgroundTaskChannel)
90
+ begin
91
+ ::BackgroundTaskChannel
85
92
  after_commit do
86
- BackgroundTaskChannel.broadcast_to(self, api_serialize)
93
+ ::BackgroundTaskChannel.broadcast_to(self, api_serialize) if api_access_allowed?
87
94
  end
95
+ rescue NameError
88
96
  end
89
97
  end
90
98
 
@@ -2,6 +2,8 @@ module Joblin
2
2
  module BackgroundTask::Attachments
3
3
  extend ActiveSupport::Concern
4
4
 
5
+ include Concerns::JobWorkingDirs
6
+
5
7
  def attachment_path(key, expires_in: true)
6
8
  if !expires_in || Rails.env.development? || Rails.env.test?
7
9
  return Rails.application.routes.url_helpers.rails_blob_path(
@@ -19,10 +19,26 @@ module Joblin
19
19
  delegate :queue_as, :sidekiq_options, to: :job_executor_class
20
20
 
21
21
  %i[before around after].each do |hook_type|
22
- define_method(:"#{hook_type}_perform") do |*args, &blk|
23
- blk ||= args[0].to_proc
24
- job_executor_class.send(:"#{hook_type}_perform") do |*args|
25
- the_task.instance_exec(&blk)
22
+ define_method(:"#{hook_type}_perform") do |*args, &callback|
23
+ callback ||= args[0]
24
+ if callback.is_a?(Symbol) || callback.is_a?(String)
25
+ job_executor_class.define_method(callback) do |*margs, &blk|
26
+ the_task.send(callback, *margs, &blk)
27
+ end
28
+ job_executor_class.send(:"#{hook_type}_perform", callback)
29
+ elsif callback.is_a?(Proc)
30
+ # Not exactly pretty...
31
+ proc = case callback.arity
32
+ when 0
33
+ -> { the_task.instance_exec(&callback) }
34
+ when 1
35
+ ->(a) { the_task.instance_exec(a, &callback) }
36
+ when 2
37
+ ->(a, b) { the_task.instance_exec(a, b, &callback) }
38
+ else
39
+ raise ArgumentError, "Unsupported callback arity #{callback.arity}"
40
+ end
41
+ job_executor_class.send(:"#{hook_type}_perform", &proc)
26
42
  end
27
43
  end
28
44
  end
@@ -6,6 +6,13 @@ module Joblin
6
6
  def bt_passthrough_values
7
7
  @bt_passthrough_values ||= (instance_methods - ActiveRecord::Base.instance_methods - %i[options= batch_id= id_value= type=]).map(&:to_s).select { |m| m.end_with?('=') }.map { |m| m[0..-2] }
8
8
  end
9
+
10
+ def new(*args, **kwargs, &blk)
11
+ options = kwargs.delete(:options) || {}
12
+ super.tap do |instance|
13
+ instance.options.merge!(options)
14
+ end
15
+ end
9
16
  end
10
17
 
11
18
  included do
data/joblin.gemspec CHANGED
@@ -25,6 +25,8 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency 'rediconn', '~> 0.1.0'
26
26
  spec.add_dependency 'rails', '>= 5', '< 9.0'
27
27
 
28
+ spec.add_dependency 'ostruct'
29
+
28
30
  spec.add_development_dependency 'rspec', '~> 3'
29
31
  spec.add_development_dependency 'redis'
30
32
  spec.add_development_dependency 'rspec-rails'
@@ -1,3 +1,3 @@
1
1
  module Joblin
2
- VERSION = "0.1.1".freeze
2
+ VERSION = "0.1.3".freeze
3
3
  end