Details

    • Type: Bug
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.1.0
    • Fix Version/s: None
    • Component/s: Jobs
    • Labels:
      None

      Description

      I'm not 100% certain that this is a bug in torquebox, but I can't see where else the bug could possibly be, and I'm pretty sure it is a bug.

      I've setup a very basic background job class, and to test it currently just outputs messages to the log. Below is the class I've setup

      job.rb
      class MyJob
      
        def initialize(opts = {})
          Rails.logger.debug "Created with opts #{opts}"
          @opts = opts
        end
       
        def run
          Rails.logger.debug "Running with opts #{@opts}"
          Rails.logger.debug "Running with sym prop #{@opts[:property]}"
          Rails.logger.debug "Running with str prop #{@opts['property']}"
          Rails.logger.debug "Running with opts class #{@opts.class}"
          Rails.logger.debug "Running with opts values #{@opts.values}"
          Rails.logger.debug "Running with opts keys #{@opts.keys}"
        end
      
      end
      

      To launch the job, I am calling

      TorqueBox::ScheduledJob.at('MyJob', at: Time.now, name: 'JobName', config: { property: 15 })
      

      I have not setup a job in the torquebox description, however this seems to be working as expected, and the job is being scheduled and is runnning at the correct time.
      For the above job, I expect to get the following output in the console

      Created with opts { property: 15 }
      Running with sym prop 15
      Running with str prop 
      Running with opts class Hash
      Running with opts values [15]
      Running with opts keys [:property]
      

      Unfortunately, the output I am actually getting is

      Created with opts { property: 15 }
      Running with sym prop
      Running with str prop 
      Running with opts class Hash
      Running with opts values [15]
      Running with opts keys [:property]
      

      Whilst it is almost exactly what I expect, the retrieval of the property value fails.
      There are no errors returned, I simply don't retrieve a value.

      To test if this was an error in my own code, I opened a rails console and manually tested it by doing the following

      j = MyJob.new({ property: 15 })
      j.run
      

      Nice and simple. When this runs, I receive the output I expect and the value is returned correctly.
      The only difference I can see here is that I am calling it directly from a rails console rather than Torquebox invoking it.

      The only solution that I could find that made it work, was to change my initialize method to the following

      def initialize(opts = {})
        opts.each do |k, v|
          self.instance_variable_set("@#{k}", v)
        end
      end
      

      Obviously this is quite a horrible solution just to retrieve a single key from a hash.

      Please let me know if this is not in fact a bug in Torquebox and I've completely missed something, but I don't see where else the problem could lie.

      I am running Torquebox 3.1.0, with Rails 4 and jRuby 1.7.11

        Gliffy Diagrams

          Attachments

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                pareeohnos Adrian Hooper
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated: