2016-04-20 18:13:36 +02:00
|
|
|
class OpenlabWorker
|
|
|
|
include Sidekiq::Worker
|
|
|
|
sidekiq_options queue: 'default', retry: true
|
|
|
|
|
|
|
|
Logger = Sidekiq.logger.level == Logger::DEBUG ? Sidekiq.logger : nil
|
2016-04-21 11:42:43 +02:00
|
|
|
OPENLAB_CLIENT = Openlab::Projects.new
|
2016-04-20 18:13:36 +02:00
|
|
|
|
|
|
|
def perform(action, project_id)
|
|
|
|
logger.debug ["Openlab sync", action, "project ID: #{project_id}"]
|
|
|
|
|
|
|
|
case action.to_s
|
|
|
|
when /create/
|
|
|
|
project = Project.find(project_id)
|
2016-04-21 11:42:43 +02:00
|
|
|
response = OPENLAB_CLIENT.create(project.openlab_attributes)
|
2016-04-20 18:13:36 +02:00
|
|
|
when /update/
|
|
|
|
project = Project.find(project_id)
|
2016-04-21 11:42:43 +02:00
|
|
|
response = OPENLAB_CLIENT.update(project_id, project.openlab_attributes)
|
2016-04-20 18:13:36 +02:00
|
|
|
when /destroy/
|
2016-04-21 11:42:43 +02:00
|
|
|
response = OPENLAB_CLIENT.destroy(project_id)
|
2016-04-20 18:13:36 +02:00
|
|
|
end
|
2016-04-21 11:42:43 +02:00
|
|
|
|
|
|
|
logger.debug ["Openlab sync", "RESPONSE ERROR", response.inspect] unless response.success?
|
2016-04-20 18:13:36 +02:00
|
|
|
end
|
|
|
|
end
|