istt / campaign-manager

1 stars 0 forks source link

Add global rate limit per VASCloud Service #5

Closed dinhtrung closed 6 years ago

dinhtrung commented 6 years ago

Allow customer to add global rate limit per VASCloud service, along with ratelimit per campaign

dinhtrung commented 6 years ago

Add following attributes to service configuration:

dinhtrung commented 6 years ago

File: VasCloudSmsSubmitCallable

public static Map<String, Bucket> bucketList = new ConcurrentHashMap<String, Bucket>();

VasCloudConfigurationDTO cfg = mapper.readValue(mapper.writeValueAsString(campaign.getCfg().get("VASCLOUD")), VasCloudConfigurationDTO.class);
        if (cfg.getRateLimit() != null) {
            Bucket svcBucket = bucketList.get(cfg.getId());
            if (svcBucket == null ) {
                svcBucket = createBucket(cfg.getRateLimit());
                bucketList.put(cfg.getId(), svcBucket);
            }
            svcBucket.asScheduler().consume(smsList.size());
        }
        createBucket(campaign.getRateLimit());