Using resque

M Mike Bennett 3 years 6 months ago
3 1 0

I have an application that is deployed using RhoConnect.  It uses a Source Adapter to synchronize photos taken in the app.  All is working well unless a user takes several photos while off line, then the sync process fails.  I've been advised by a Zebra expert that using resque will solve this issue.

I'm using RhoConnect 5.1.1, but the application has been ported from version 4.1.0

I've tried to follow the documentation but have the following issues:

Attempting to start a resque worker using the command

QUEUE=* rake resque:work

fails with the error

LoadError: cannot load such file -- rhoconnect/tasks

If I edit the Rakefile and comment out the line

require 'rhoconnect/tasks'

I'm able to start a worker.  Is this the correct thing to do?

Now after editing settings.yml and adding

Image:
:queue: image_queue

under :sources:

I successfully get a job for the worker to process, but this job fails with the following details

Worker B-P-MOBILE-APP2:10835
Class Rhoconnect::SourceJob
Arguments

--- query
... 
--- Image
...
--- application
...
--- 40001-05-8765-AB3
...
---
...
Exception ArgumentError
Error Unknown source
/opt/rhoconnect/lib/ruby/gems/2.2.0/gems/rhoconnect-5.1.1/lib/rhoconnect/handler/query/engine.rb:12:in `initialize' /opt/rhoconnect/lib/ruby/gems/2.2.0/gems/rhoconnect-5.1.1/lib/rhoconnect/jobs/source_job.rb:15:in `new' /opt/rhoconnect/lib/ruby/gems/2.2.0/gems/rhoconnect-5.1.1/lib/rhoconnect/jobs/source_job.rb:15:in `perform'
The code for the Image model is:

class Image Rhoconnect::Model::Base
  #include Rhoconnectrb::Resource

  @@photosFolder = "/opt/nginx/html/photos"

  def initialize(source)
    super(source)
  end

  def login
    # TODO: Login to your data source here if necessary
  end

  def query(params=nil)

    records = DbImage.where(["deviceid = ?", current_user.login])
    @result = Hash.new
    hash_index = 1
    if records != nil
        records.each do |record|

            @result[hash_index.to_s] = record.as_json

            @result[hash_index.to_s].delete("image_uri")

            hash_index = hash_index + 1

          end
    end

    puts @result

    return @result
  end

  def create(create_hash)
    # Create a new record in your backend data source
    puts "create_hash: #{create_hash}"

    name = create_hash["image_uri"]

    # filename we saved in application.rb#store_blob method
    basename = create_hash["filename"]

    DbImage.create(create_hash)

    return create_hash["filename"]
  end

  def update(update_hash)
    # TODO: Update an existing record in your backend data source
  end

  def delete(delete_hash)
    record = DbImage.where("uniqueid = ?", delete_hash['uniqueid'])
    if record.length == 1
      record.delete(delete_hash['uniqueid'])
    end
  end

  def logoff
    # TODO: Logout from the data source if necessary
  end

  def store_blob(object,field_name,blob)
    root_path = "/"
    file_name = blob[:filename]

    # Save the file to the path
    from = blob[:tempfile].path
    to = "#{@@photosFolder}/#{blob[:filename].to_s}"

    # Create folder path if it doesn't exist
    if (!File.directory?(to))
        FileUtils.mkdir_p(File.dirname(to))
    end

    #Copy file
    FileUtils.cp(from, to)

    #Change file permissions so that it is readable by everyone
    File.chmod(0666, to)

    #Change group and owner to planetrails so that it can delete the file after processing
    ownerId = `id -u planetrails`
    groupId = `id -g planetrails`
    File.chown(ownerId.to_i, groupId.to_i, to)

    object['filename'] = blob[:filename].to_s
  end
end

What am I missing?

Please Register or Login to post a reply

1 Replies

M Mark Nongkhlaw

Maybe you should post this in RhoConnect Discussions instead of RhoMobile Discussions

CONTACT
Can’t find what you’re looking for?