rocketjob 5.0.0.beta3 → 5.0.0.beta4

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: 3a9461707111b2196affa91073e002da7664503f5a31aa1718745502e8b677ed
4
- data.tar.gz: b1aff5d9bd88c754de93454f699821f5d598767e30830d3456ff289ae0ed7525
3
+ metadata.gz: '048d247981e5131c03505a00a99945bc9efb9a1d862d629a5da1db9bbd2aa083'
4
+ data.tar.gz: 361373a9b8a8709276fc9198be95bd7f197b54c7dc067e59d91d2f648f13653f
5
5
  SHA512:
6
- metadata.gz: c61f05e4bd981ce85d199758bc6211256f9fa1408196c9f0168821d79ba8eb4d9e403db2fa91ed5de4a00b20545aadca051bdbd3fd586b9340c6e06430c91f28
7
- data.tar.gz: 4ba190a069d7fa2ed7f0a684e1f32e6d7ff6f6a6838df8d082016cecc62d83207522393e6bca0c7a25370a8bfb0986a3f4db51a055a8629df4fa10f8fcac57f6
6
+ metadata.gz: e955117f6a72063a9de9bbea3d7ced0e1e4afa1943ff72af5f443f9fc1b2c59babeb687fc0d3924892635a328605b9421b11ee3ea18de2681f159be95595ebcf
7
+ data.tar.gz: e22f2bea9056da23229a29cc6fd6005dc09d8ae0a73b8bac30704636ace2cd7d347c1cfa8fcffed89680fe6b591eb77dfbeb925185594330772f11c8f8b53b29
@@ -57,7 +57,7 @@ module RocketJob
57
57
  #
58
58
  # I.e. Not during before_batch and after_batch.
59
59
  def pausable?
60
- queued? || paused? || running? && (sub_state == :processing)
60
+ queued? || paused? || (running? && (sub_state == :processing))
61
61
  end
62
62
 
63
63
  private
@@ -0,0 +1,104 @@
1
+ # Copy the source_url file/url/path to the target file/url/path.
2
+ #
3
+ # Example: Upload a file to an SFTP Server:
4
+ #
5
+ # RocketJob::Jobs::CopyFileJob.create!(
6
+ # source_url: "/exports/uploads/important.csv.pgp",
7
+ # target_url: "sftp://sftp.example.org/uploads/important.csv.pgp",
8
+ # target_args: {
9
+ # username: "Jack",
10
+ # password: "OpenSesame",
11
+ # ssh_options: {
12
+ # IdentityFile: "~/.ssh/secondary"
13
+ # }
14
+ # }
15
+ # )
16
+ #
17
+ # Notes:
18
+ # - The password is only encrypted when the Symmetric Encryption gem has been installed.
19
+ # - If `decrypt: true` then the file will be decrypted with Symmetric Encryption,
20
+ # prior to uploading to the sftp server.
21
+ module RocketJob
22
+ module Jobs
23
+ class CopyFileJob < RocketJob::Job
24
+ include RocketJob::Plugins::Retry
25
+
26
+ self.destroy_on_complete = false
27
+ # Number of times to automatically retry the copy. Set to `0` for no retry attempts.
28
+ self.retry_limit = 5
29
+
30
+ # File names in IOStreams URL format.
31
+ field :source_url, type: String, user_editable: true
32
+ field :target_url, type: String, user_editable: true
33
+
34
+ # Any optional arguments to pass through to the IOStreams source and/or target.
35
+ field :source_args, type: Hash, default: -> { {} }
36
+ field :target_args, type: Hash, default: -> { {} }
37
+
38
+ # Any optional IOStreams streams to apply to the source and/or target.
39
+ field :source_streams, type: Hash, default: -> { {none: nil} }
40
+ field :target_streams, type: Hash, default: -> { {none: nil} }
41
+
42
+ # Data to upload, instead of supplying `:input_file_name` above.
43
+ # Note: Data must be less than 15MB after compression.
44
+ if defined?(SymmetricEncryption)
45
+ field :encrypted_source_data, type: String, encrypted: {random_iv: true, compress: true}
46
+ else
47
+ field :source_data, type: String
48
+ end
49
+
50
+ validates_presence_of :source_url, unless: :source_data
51
+ validates_presence_of :target_url
52
+ validates_presence_of :source_data, unless: :source_url
53
+
54
+ before_save :set_description
55
+
56
+ def perform
57
+ if source_data
58
+ target_path.write(source_data)
59
+ elsif target_url
60
+ target_path.copy_from(source_path)
61
+ end
62
+
63
+ self.percent_complete = 100
64
+ end
65
+
66
+ private
67
+
68
+ def set_description
69
+ self.description = "Copying to #{target_url}"
70
+ end
71
+
72
+ def source_path
73
+ source = IOStreams.path(source_url, **decrypt_args(source_args))
74
+ apply_streams(source, source_streams)
75
+ source
76
+ end
77
+
78
+ def target_path
79
+ target = IOStreams.path(target_url, **decrypt_args(target_args))
80
+ apply_streams(target, target_streams)
81
+ target
82
+ end
83
+
84
+ def apply_streams(path, streams)
85
+ streams.each_pair { |stream, args| path.stream(stream.to_sym, args.nil? ? {} : decrypt_args(args)) }
86
+ end
87
+
88
+ def decrypt_args(args)
89
+ return args.symbolize_keys unless defined?(SymmetricEncryption)
90
+
91
+ decrypted_args = {}
92
+ args.each_pair do |key, value|
93
+ if key.to_s.start_with?("encrypted_")
94
+ unencrypted_key = key.to_s.sub("encrypted_", "")
95
+ decrypted_args[unencrypted_key.to_sym] = SymmetricEncryption.decrypt(value)
96
+ else
97
+ decrypted_args[key.to_sym] = value
98
+ end
99
+ end
100
+ decrypted_args
101
+ end
102
+ end
103
+ end
104
+ end
@@ -1,12 +1,6 @@
1
1
  require 'fileutils'
2
2
  require 'uri'
3
3
 
4
- begin
5
- require 'iostreams'
6
- rescue LoadError
7
- # Optional dependency
8
- end
9
-
10
4
  module RocketJob
11
5
  module Jobs
12
6
  # Job to upload a file into another job.
@@ -93,12 +87,12 @@ module RocketJob
93
87
  end
94
88
 
95
89
  def file_exists
96
- return if upload_file_name.nil?
90
+ return if upload_file_name.nil?
97
91
  uri = URI.parse(upload_file_name)
98
92
  return unless uri.scheme.nil? || uri.scheme == 'file'
99
- return if File.exist?(upload_file_name)
93
+ return if File.exist?(upload_file_name)
100
94
  errors.add(:upload_file_name, "Upload file: #{upload_file_name} does not exist.")
101
95
  end
102
- end
96
+ end
103
97
  end
104
98
  end
@@ -111,6 +111,11 @@ module RocketJob
111
111
  end
112
112
  end
113
113
 
114
+ # All regular jobs can be paused or resumed whilst queued.
115
+ def self.pausable?
116
+ queued? || paused? || pausable
117
+ end
118
+
114
119
  private
115
120
 
116
121
  # Sets the exception child object for this job based on the
@@ -1,3 +1,3 @@
1
1
  module RocketJob
2
- VERSION = '5.0.0.beta3'.freeze
2
+ VERSION = '5.0.0.beta4'.freeze
3
3
  end
@@ -64,6 +64,7 @@ module RocketJob
64
64
 
65
65
  module Jobs
66
66
  autoload :ActiveJob, 'rocket_job/jobs/active_job'
67
+ autoload :CopyFileJob, 'rocket_job/jobs/copy_file_job'
67
68
  autoload :DirmonJob, 'rocket_job/jobs/dirmon_job'
68
69
  autoload :OnDemandBatchJob, 'rocket_job/jobs/on_demand_batch_job'
69
70
  autoload :OnDemandJob, 'rocket_job/jobs/on_demand_job'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rocketjob
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0.beta3
4
+ version: 5.0.0.beta4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Reid Morrison
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-04 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aasm
@@ -128,6 +128,7 @@ files:
128
128
  - lib/rocket_job/job.rb
129
129
  - lib/rocket_job/job_exception.rb
130
130
  - lib/rocket_job/jobs/active_job.rb
131
+ - lib/rocket_job/jobs/copy_file_job.rb
131
132
  - lib/rocket_job/jobs/dirmon_job.rb
132
133
  - lib/rocket_job/jobs/housekeeping_job.rb
133
134
  - lib/rocket_job/jobs/on_demand_batch_job.rb