Class: VCAP::Services::Base::AsyncJob::Serialization::BaseCreateSerializedURLJob
- Inherits:
-
SerializationJob
- Object
- SerializationJob
- VCAP::Services::Base::AsyncJob::Serialization::BaseCreateSerializedURLJob
- Defined in:
- lib/base/job/serialization.rb
Overview
Generate download URL for a service snapshot
Constant Summary collapse
- VALID_CREDENTIAL_CHARACTERS =
("A".."Z").to_a + ("a".."z").to_a + ("0".."9").to_a
Constants included from VCAP::Services::Base::AsyncJob::Snapshot
VCAP::Services::Base::AsyncJob::Snapshot::FILTER_KEYS, VCAP::Services::Base::AsyncJob::Snapshot::MAX_NAME_LENGTH, VCAP::Services::Base::AsyncJob::Snapshot::SNAPSHOT_ID, VCAP::Services::Base::AsyncJob::Snapshot::SNAPSHOT_KEY_PREFIX
Constants included from VCAP::Services::Base::AsyncJob::Serialization
Instance Attribute Summary
Attributes inherited from SerializationJob
Instance Method Summary collapse
- #cleanup(name, snapshot_id) ⇒ Object
-
#execute ⇒ Object
empty.
- #generate_download_token(length = 12) ⇒ Object
- #generate_download_url(name, snapshot_id, token) ⇒ Object
-
#perform ⇒ Object
workflow template.
Methods inherited from SerializationJob
#create_lock, #delete_download_token, #get_dump_path, #handle_error, #init_worker_logger, #initialize, #parse_config, queue_lookup_key, #required_options, select_queue, #snapshot_filename, #update_download_token, #validate_input
Methods included from Error
#failure, #internal_fail, #parse_msg, #success, #timeout_fail
Methods included from VCAP::Services::Base::AsyncJob::Snapshot
#client, #delete_snapshot, #filter_keys, #fmt_time, #new_snapshot_id, redis_connect, redis_init, #save_snapshot, #service_snapshots, #service_snapshots_count, #snapshot_details, #snapshot_filepath, #update_name
Methods included from VCAP::Services::Base::AsyncJob::Serialization
#fmt_error, redis_connect, #redis_key
Constructor Details
This class inherits a constructor from VCAP::Services::Base::AsyncJob::Serialization::SerializationJob
Instance Method Details
#cleanup(name, snapshot_id) ⇒ Object
182 183 184 185 186 187 188 189 |
# File 'lib/base/job/serialization.rb', line 182 def cleanup(name, snapshot_id) return unless (name && snapshot_id) begin delete_download_token(name, snapshot_id) rescue => e @logger.error("Error in cleanup: #{e}") end end |
#execute ⇒ Object
empty
178 179 180 |
# File 'lib/base/job/serialization.rb', line 178 def execute true end |
#generate_download_token(length = 12) ⇒ Object
191 192 193 |
# File 'lib/base/job/serialization.rb', line 191 def generate_download_token(length=12) Array.new(length) { VALID_CREDENTIAL_CHARACTERS[rand(VALID_CREDENTIAL_CHARACTERS.length)] }.join end |
#generate_download_url(name, snapshot_id, token) ⇒ Object
195 196 197 198 |
# File 'lib/base/job/serialization.rb', line 195 def generate_download_url(name, snapshot_id, token) url_template = @config["download_url_template"] url_template % {:service => @config["service_name"], :name => name, :snapshot_id => snapshot_id, :token => token} end |
#perform ⇒ Object
workflow template
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
# File 'lib/base/job/serialization.rb', line 148 def perform begin :service_id, :snapshot_id @name = ["service_id"] @snapshot_id = ["snapshot_id"] @logger.info("Launch job: #{self.class} for #{name} with options:#{.inspect}") lock = create_lock lock.lock do result = execute @logger.info("Results of create serialized url: #{result}") token = generate_download_token() update_download_token(name, @snapshot_id, token) url = generate_download_url(name, @snapshot_id, token) @logger.info("Download link generated for snapshot=#{@snapshot_id} of #{name}: #{url}") job_result = { :url => url } completed(Yajl::Encoder.encode(job_result)) @logger.info("Complete job: #{self.class} for #{name}") end rescue => e cleanup(name, @snapshot_id) handle_error(e) ensure set_status({:complete_time => Time.now.to_s}) end end |