Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sync start #66

Merged
merged 5 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion commands/sync/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const watch = require('./watch');
const create = require('./create');
const start = require('./start');
const stop = require('./stop');

module.exports = {
watch,
create
create,
start,
stop
};
46 changes: 46 additions & 0 deletions commands/sync/start.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const { post } = require('../../helpers/request-helper');

const startHandler = async ({ endpoint, rejectUnauthorized, algorithmName, devFolder, $0: appName }) => {
// get all parameters, decorate,
const body = {
name: algorithmName,
options: {
devMode: true,
devFolder
}
};
// send update, if doesn't exist, exit.
const res = await post({ endpoint, rejectUnauthorized, path: 'store/algorithms?overwrite=true', body });
if (res.result.error || res.error) {
let msg;
msg = res.result.error.message.includes('missing') ? "algorithm doesn't exist" : msg = res.result.error.message;
console.log(`code: ${res.result.error.code}, message: ${msg}`);
return;
}
console.log(`algorithm ${algorithmName} modified to be in development mode.`);
console.log('to sync the folder to the algorithm run');
console.log(`${appName} sync watch -a ${algorithmName} -f localAlgoFolder`);
};
module.exports = {
command: 'start',
description: 'start an existing algorithm in development mode',
options: {
},
builder: {
algorithmName: {
demandOption: true,
describe: 'The name of the algorithm to sync files into',
type: 'string',
alias: ['a']
},
devFolder: {
demandOption: true,
describe: 'folder in pod to sync to',
type: 'string',
alias: ['f']
}
},
handler: async (argv) => {
await startHandler(argv);
}
};
38 changes: 38 additions & 0 deletions commands/sync/stop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
const { post } = require('../../helpers/request-helper');

const stopHandler = async ({ endpoint, rejectUnauthorized, algorithmName }) => {
// get all parameters, decorate,
const body = {
name: algorithmName,
options: {
devMode: false,
devFolder: null
}
};
// send update, if doesn't exist, exit.
const res = await post({ endpoint, rejectUnauthorized, path: 'store/algorithms?overwrite=true', body });
if (res.result.error || res.error) {
let msg;
msg = res.result.error.message.includes('missing') ? "algorithm doesn't exist" : msg = res.result.error.message;
console.log(`code: ${res.result.error.code}, message: ${msg}`);
return;
}
console.log(`algorithm ${algorithmName} removed from development mode.`);
};
module.exports = {
command: 'stop',
description: 'removes an algorithm from development mode',
options: {
},
builder: {
algorithmName: {
demandOption: true,
describe: 'The name of the algorithm to stop syncing files into',
type: 'string',
alias: ['a']
}
},
handler: async (argv) => {
await stopHandler(argv);
}
};
Loading