Skip to content

Commit

Permalink
[IMPROVE] Connectivity Services License Sync (#15022)
Browse files Browse the repository at this point in the history
* Add workspace sync to cron job to keep license, access token, and marketplace key in sync
  • Loading branch information
geekgonecrazy authored and sampaiodiego committed Jul 19, 2019
1 parent 0c244c5 commit 30d671b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/cloud/server/functions/getWorkspaceLicense.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { HTTP } from 'meteor/http';
import { getWorkspaceAccessToken } from './getWorkspaceAccessToken';
import { settings } from '../../../settings';
import { Settings } from '../../../models';
import { callbacks } from '../../../callbacks';


export function getWorkspaceLicense() {
Expand Down Expand Up @@ -39,5 +40,7 @@ export function getWorkspaceLicense() {

Settings.updateValueById('Cloud_Workspace_License', remoteLicense.license);

callbacks.run('workspaceLicenseChanged', remoteLicense.license);

return { updated: true, license: remoteLicense.license };
}
22 changes: 20 additions & 2 deletions app/cloud/server/index.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
import { Meteor } from 'meteor/meteor';
import { SyncedCron } from 'meteor/littledata:synced-cron';

import './methods';
import { getWorkspaceAccessToken } from './functions/getWorkspaceAccessToken';
import { getWorkspaceLicense } from './functions/getWorkspaceLicense';
import { getUserCloudAccessToken } from './functions/getUserCloudAccessToken';
import { getWorkspaceKey } from './functions/getWorkspaceKey';
import { syncWorkspace } from './functions/syncWorkspace';
import { Permissions } from '../../models';

if (Permissions) {
Permissions.createOrUpdate('manage-cloud', ['admin']);
}

// Ensure the client/workspace access token is valid
getWorkspaceAccessToken();
const licenseCronName = 'Cloud Workspace Sync';

Meteor.startup(function() {
// run token/license sync if registered
syncWorkspace();

SyncedCron.remove(licenseCronName);
SyncedCron.add({
name: licenseCronName,
schedule(parser) {
// Every 12 hours
return parser.cron('0 */12 * * *');
},
job: syncWorkspace,
});
});

export { getWorkspaceAccessToken, getWorkspaceLicense, getWorkspaceKey, getUserCloudAccessToken };

0 comments on commit 30d671b

Please sign in to comment.