Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Periodically poll marketplace catalog

Change-Id: I91b8b4213091b28049ee4b36699ac000b9d7418c
  • Loading branch information...
commit 16a3eb5452f2a06b83340951027f5b2e25345c22 1 parent 66eead3
Harshawardhan Gadgil authored
View
2  marketplace/config/marketplace_gateway.yml
@@ -15,3 +15,5 @@ pid: /var/vcap/sys/run/marketplace.pid
marketplace: appdirect
acls: [ "*@example.com" ]
+
+refresh_interval: 300
View
36 marketplace/lib/base/marketplace_async_gateway.rb
@@ -48,6 +48,8 @@ def setup(opts)
@proxy_opts = opts[:proxy]
@handle_fetched = true # set to true in order to compatible with base asycn gateway.
+ @refresh_interval = opts[:refresh_interval] || 300
+
@marketplace_client = load_marketplace(opts)
@catalog = {}
@@ -66,8 +68,28 @@ def setup(opts)
end
end
+ @refresh_timer = EM::PeriodicTimer.new(@refresh_interval) do
+ refresh_catalog_and_update_cc
+ end
+
##### Start up
@ready_to_serve = false
+
+ refresh_catalog_and_update_cc
+ @ready_to_serve = true
+ end
+
+ error [JsonMessage::ValidationError, JsonMessage::ParseError] do
+ error_msg = ServiceError.new(ServiceError::MALFORMATTED_REQ).to_hash
+ abort_request(error_msg)
+ end
+
+ not_found do
+ error_msg = ServiceError.new(ServiceError::NOT_FOUND, request.path_info).to_hash
+ abort_request(error_msg)
+ end
+
+ def refresh_catalog_and_update_cc
f = Fiber.new do
begin
# get all service offerings
@@ -76,24 +98,13 @@ def setup(opts)
advertise_services
# Ready to serve
@logger.info("#{@marketplace_client.name} Marketplace Gateway is ready to serve incoming request.")
- @ready_to_serve = true
rescue => e
- @logger.fatal("Error when start up: #{fmt_error(e)}")
+ @logger.fatal("Error when refreshing #{@marketplace_client.name} catalog: #{fmt_error(e)}")
end
end
f.resume
end
- error [JsonMessage::ValidationError, JsonMessage::ParseError] do
- error_msg = ServiceError.new(ServiceError::MALFORMATTED_REQ).to_hash
- abort_request(error_msg)
- end
-
- not_found do
- error_msg = ServiceError.new(ServiceError::NOT_FOUND, request.path_info).to_hash
- abort_request(error_msg)
- end
-
def refresh_catalog
@catalog = @marketplace_client.get_catalog
end
@@ -107,6 +118,7 @@ def advertise_services(active=true)
def on_exit(stop_event_loop=true)
@ready_to_serve = false
+ @refresh_timer.cancel
Fiber.new {
# Since the services are not being stored locally
refresh_catalog
Please sign in to comment.
Something went wrong with that request. Please try again.