Sha256: 45040e65339ad2b3a416f48e5f17d9f1b73b50cf4010511af67a0b609e43bedf
Contents?: true
Size: 1 KB
Versions: 1
Compression:
Stored size: 1 KB
Contents
require 'json' require 'rack' module RailsCloudTasks module Rack class Tasks class << self def call(env) request = ::Rack::Request.new(env) job = extract_job(request) RailsCloudTasks::Instrumentation.transaction_name!( "RailsCloudTasks/#{job['job_class']}/perform_now" ) RailsCloudTasks::Instrumentation.add_custom_attributes( { request_body: job['arguments'] } ) ActiveJob::Base.execute(job) response(200, {}) rescue Rack::InvalidPayloadError => e response(400, { error: e.cause.message }) end private def extract_job(request) body = request.body.read JSON.parse(body).fetch('job') rescue JSON::ParserError, KeyError raise Rack::InvalidPayloadError end def response(status, body) [status, { 'Content-Type' => 'application/json' }, [body.to_json]] end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
rails-cloud-tasks-0.0.10 | lib/rails_cloud_tasks/rack/tasks.rb |