Skip to content

Commit

Permalink
505 current version endpoint (#512)
Browse files Browse the repository at this point in the history
* Spelling fixes in management

* added endpoint to management which exposes the latest version

* Changed api to use the new endpoint in management

* Review fixes

* Small review fix
  • Loading branch information
michaelkruglos committed Jul 25, 2017
1 parent 33a0cb3 commit 96ce5af
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class TweekManagementRulesDriver : IRulesDriver, IDisposable
{
public event Action<IDictionary<string, RuleDefinition>> OnRulesChange;
private const string RULESET_PATH = "/ruleset/latest";
private const string RULESET_LATEST_VERSION_PATH = "/ruleset/latest/version";
private IDisposable _subscrption;
private readonly IConnectableObservable<Dictionary<string, RuleDefinition>> _pipeline;
public string CurrentLabel { get; private set; }
Expand Down Expand Up @@ -73,15 +74,17 @@ private TweekManagementRulesDriver(HttpGet getter, TweekManagementRulesDriverSet
{
while (!shouldStop)
{
var response = await measuredGetter(RULESET_PATH);
var newVersion = response.GetRulesVersion();
LastCheckTime = DateTime.UtcNow;
if (newVersion == CurrentLabel)
var versionResponse = await measuredGetter(RULESET_LATEST_VERSION_PATH);
var latestVersion = await versionResponse.Content.ReadAsStringAsync();
if (latestVersion == CurrentLabel)
{
await Delay(settings.SampleInterval, scheduler);
continue;
}
var ruleset = await measuredDownloader(response);
var rulesetResponse = await getter(RULESET_PATH);
var newVersion = rulesetResponse.GetRulesVersion();
LastCheckTime = DateTime.UtcNow;
var ruleset = await measuredDownloader(rulesetResponse);
sub.OnNext(ruleset);
CurrentLabel = newVersion;
}
Expand Down
4 changes: 2 additions & 2 deletions services/management/src/rulesCache.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const gitPublicKey = nconf.get('GIT_PUBLIC_KEY_PATH');
const gitPrivateKey = nconf.get('GIT_PRIVATE_KEY_PATH');

if (!gitUrl || !gitUser) {
throw 'missing rules repostiroy details';
throw 'missing rules repository details';
}

const repoPath = `${process.env.RULES_DIR || os.tmpdir()}/tweek-rules-${Guid.raw()}`;
Expand Down Expand Up @@ -79,7 +79,7 @@ async function updateLatestCache() {
rulesCache.ruleset = ruleset;
const timer = logger.startTimer();
rulesCache.formattedRuleset = JSON.stringify(ruleset);
timer.done("updateLatestCache:JSON.stringify")
timer.done('updateLatestCache:JSON.stringify');
logger.info('Rules Cache updated', { sha: newLatestSha });
} catch (err) {
console.error(err);
Expand Down
12 changes: 11 additions & 1 deletion services/management/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,20 @@ app.get('/ruleset/latest', (req, res) => {
}

res.header('X-Rules-Version', rulesCache.getLatestRulesVersion());
res.contentType("application/json");
res.contentType('application/json');
res.send(rulesCache.getLatestFormattedRules());
});

app.get('/ruleset/latest/version', (req, res) => {
if (!rulesCache.getLatestRulesVersion()) {
res.status(503).send('Git repository not ready yet');
return;
}

res.contentType('text/plain');
res.send(rulesCache.getLatestRulesVersion());
});

app.get('/isalive', bodyParser.json(), (req, res) => res.send('alive'));

rulesCache.buildLocalCache();
Expand Down

0 comments on commit 96ce5af

Please sign in to comment.