I need to use sanitization in Jobs, so i wrote method
def sanitized_sql_statement(query)
ActiveRecord::Base.send(
:sanitize_sql_array,
query
)
end
I have 2 different job files. Where I should place this method and how to use it from Jobs?
Active Job is a framework for declaring jobs and making them run on a variety of queueing backends. These jobs can be everything from regularly scheduled clean-ups, to billing charges, to mailings. Anything that can be chopped up into small units of work and run in parallel, really.
Enqueue jobs The different enqueuing options are the following: wait : With this, the job is enqueued after the mentioned time period. wait_until : With this, the job is enqueued after that the specified time has elapsed. queue : With this, the job is added to the specified queue.
Often in the 'Rails world' a worker is referring to a priority queue type system that has separate processes popping off tasks to execute outside the application cycle. One of the most popular of these systems is DelayedJobs.
In the background the server can process all background jobs one by one. Rails provides Active Job to process background jobs and making them run on a variety of queueing applications.
Use concern
.
create concerns directory under jobs directory app/jobs/concerns
like models and controllers do.
write concern file.
module SqlSanitizer
extend ActiveSupport::Concern
def sanitized_sql_statement(query)
ActiveRecord::Base.send(
:sanitize_sql_array,
query
)
end
end
And include in your job
class YourJob < ActiveJob::Base
include SqlSanitizer
# ... do something
end
If you fail to auto load SqlSanitizer, add autoload path in config/application.rb file => config.autoload_paths << "#{Rails.root}/app/jobs/concerns"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With