module AwsCron::Controller
Public Instance Methods
aws_time_provider()
click to toggle source
# File lib/aws_cron/controller.rb, line 15 def aws_time_provider @aws_time_provider end
run() { || ... }
click to toggle source
Runs block and ensures error logging and proper JSON return
# File lib/aws_cron/controller.rb, line 21 def run(&block) yield rescue => exception AwsCron::log(:error, exception) ensure return_object end
run_in_tz(cron_str) { || ... }
click to toggle source
Runs block using defined timezone for cron scheduling and ensures error logging and proper JSON return
For tasks that call this method, make sure to have cron.yaml call this task in way that allows it to check programmatically if it needs to be triggered
# File lib/aws_cron/controller.rb, line 35 def run_in_tz(cron_str, &block) run do CronRunner.new(cron_str, self.class.aws_time_provider || time_provider || Time).run do yield end end end
timezone(name)
click to toggle source
# File lib/aws_cron/controller.rb, line 11 def timezone(name) @aws_time_provider = ActiveSupport::TimeZone.new(name) end
Protected Instance Methods
return_object()
click to toggle source
# File lib/aws_cron/controller.rb, line 45 def return_object if respond_to?(:render) # Check for ActionController::Rendering render :json => {message: 'ok'} else raise SecurityError('You must implement return_object with a 200 HTTP response using your preferred web framework') end end
time_provider()
click to toggle source
Please use timezone
, unless you need a custom time provider.
# File lib/aws_cron/controller.rb, line 54 def time_provider end