I have two model classes as follows:
class FileInfo < ActiveRecord::Base
STATUS = {:UNAPPROVED => 1, :APPROVED => 2, :PROCESSED => 3 }
attr_accessible :id, :status
validates :status, :inclusion => {:in => STATUS.values} end
FileInfo has id and status fields. Each file can multiple file-entries
(rows) of the type FileEntry. FileEntry has id, file_info_id (foreign key
of FileInfo) and status fields.
class FileEntry < ActiveRecord::Base
STATUS = {:UNAPPROVED => 1, :READY => 2 , :SENT => 3 }
attr_accessible :id, :file_info_id, :status, :reason
validates :status, :inclusion => {:in => STATUS.values}end
I want to write a worker to asynchronously process all files whose status
field is APPROVED (FileInfo model). Each of the thread should process all
file-entries for that particular file whose status is READY. The thread
should finish once all the entries are processed for that file. Assuming
that File-entries having status UNAPPROVED will also become READY.
Once each entry is processed, its status should be updated as SENT. Once
all the file-entries all have SENT status for a particular file, update
that file's status as PROCESSED.
I have code this much so far. Not able to figure out how to code the worker:
class FileInfoObserver < ActiveRecord::Observer
def after_save(fileinfo)
if fileinfo.status.eql? "APPROVED"
FileInfoWorker.perform_async datainfo.id
end
endend
The worker is as follows:
class DataInfoWorker
include Sidekiq::Worker
def perform(fileinfo)
fileinfo_id = DataInfo.find fileinfo.id
// Need to implement the logic here
endend
How should I go about it?
--
You received this message because you are subscribed to the Google Groups
"GitLab" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/gitlabhq/50f886bc-870a-4f87-9ea7-27394abb3ded%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.