String value is converted to Time object when model method is called using lazy work
I am using a held job for queue a Model
in another Model
like this:
article_loader.rb
date_value_in_string = "2017-06-21 07:17:00"
Article.delay(:queue => 'article_load').article_loading([date_value_in_string])
Even if I passed String
as an argument to a method, inside the method it gets converted to an object Time
.
article.rb
def self.article_loading(args)
date_value = args[0]
p date_value.class # Time
end
I don't know why this is happening. Any help would be appreciated.
source to share
This is because the string looks like a datetime to the default Ruby YAML loader. DelayedJob uses YAML for serialization, so this aspect comes into play.
If you want the line to be a line, put in some indentation to start with, for example x
or something. This is followed by a demo.
Consider this 1.yml
:
ds: 2017-06-21 07:17:00
then in IRB do a:
>> require "yaml"
>> YAML.load_file("1.yml")
=> {"ds"=>2017-06-21 11:17:00 +0400}
>> _["ds"].class
=> Time
source to share