[IMPROVE] Connectivity Services License Sync (#15022)

* Add workspace sync to cron job to keep license, access token, and marketplace key in sync
pull/15006/head^2
Aaron Ogle 6 years ago committed by Diego Sampaio
parent 0c244c5c4e
commit 30d671bd18
  1. 3
      app/cloud/server/functions/getWorkspaceLicense.js
  2. 22
      app/cloud/server/index.js

@ -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() {
@ -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 };
}

@ -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 };

Loading…
Cancel
Save