Skip to content

Commit

Permalink
Merge pull request #125 from rolldone/working
Browse files Browse the repository at this point in the history
Working
  • Loading branch information
rolldone authored Jul 4, 2022
2 parents c7aa4ab + 5668c65 commit a49cd23
Show file tree
Hide file tree
Showing 8 changed files with 242 additions and 41 deletions.
69 changes: 69 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"dotenv": "^8.2.0",
"eventemitter2": "^6.4.4",
"filendir": "^2.0.1",
"folder-encrypt": "^1.1.7",
"gulp": "^4.0.2",
"ignore": "^5.1.8",
"inquirer": "^8.2.0",
Expand Down
18 changes: 17 additions & 1 deletion src/app/devsync/compute/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,12 @@ export default class Uploader {
// debug: true
});
this.client.on('close', () => {
this.connect(callback);
setTimeout(()=>{
if(this.client == null){
return;
}
this.connect(callback);
},1000);
})
callback(null, 'Connected');
} catch (ex) {
Expand All @@ -573,6 +578,7 @@ export default class Uploader {
_exeHandlePush: Function = null;
clientClose(): void {
this.client.end();
this.client = null;
}
async _executeCommand(whatCommand: string, callback?: Function) {
try {
Expand Down Expand Up @@ -654,6 +660,12 @@ export default class Uploader {
debounceClose();
}
return (entry: any, first_time_out: number) => {

if(this.client == null){
this._pendingQueue = {};
return;
}

this._orders[entry.queue_no] = Object.create({
...entry,
queue_no: entry.queue_no
Expand Down Expand Up @@ -689,6 +701,10 @@ export default class Uploader {
var fileName = entry.fileName;
var action = entry.action;

if(this.client == null){
return;
}

switch (action) {
case 'add_change':
/* Check the size of file first */
Expand Down
3 changes: 2 additions & 1 deletion src/app/devsync/services/DevSyncService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,7 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({
this.watcher = null;

/* Restart the syncronize */
this.uploader.clientClose();
this.uploader.onListener('RESTART', {});
this.uploader = null;

Expand All @@ -634,7 +635,7 @@ const DevSyncService = BaseService.extend<DevSyncServiceInterface>({

setTimeout(() => {
this.construct(this._cli);
}, 3000);
}, 1000);
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down
13 changes: 9 additions & 4 deletions src/app/devsync2/compute/HttpEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { CliInterface } from "../services/CliService";
var size = require('window-size');
import os from 'os';
import { ConfigInterface } from "./Config";
import { fstatSync, readFileSync, Stats, statSync, writeFileSync } from "fs";
import { existsSync, fstatSync, readFileSync, Stats, statSync, writeFileSync } from "fs";
import parseGitIgnore from '@root/tool/parse-gitignore'
import ignore from 'ignore'
import { uniq } from "lodash";
Expand Down Expand Up @@ -336,7 +336,7 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
try {
// await this._client.delete(remoteFilePath);
await this._client.mkdir(path.dirname(remoteFilePath));
} catch (ex) {
} catch (ex) {
console.log(ex);
}
try {
Expand Down Expand Up @@ -371,14 +371,19 @@ const HttpEvent = BaseModel.extend<Omit<HttpEventInterface, 'model'>>({
generateSSHConfig() {
let _direct_access: DirectAccessType = this._config.direct_access as any;
let _configFilePath = upath.normalizeSafe(os.homedir() + '/.ssh/config');

let _privateKey = null;
if (existsSync(upath.normalize(process.cwd() + "/" + this._config.privateKey)) == true) {
_privateKey = upath.normalize(process.cwd() + "/" + this._config.privateKey);
} else {
_privateKey = this._config.privateKey
}
/* Persisten ssh_config */
let ssh_confi = {
Host: "temp_reverse_port_ssh",
HostName: this._config.host,
User: this._config.username,
Port: this._config.port,
IdentityFile: this._config.privateKey,
IdentityFile: _privateKey,
RequestTTY: "force",
StrictHostKeyChecking: "no"
}
Expand Down
12 changes: 12 additions & 0 deletions src/app/devsync2/compute/Uploader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,28 @@ export class Uploader extends DevSyncUploader {
debounceClose();
}
return (entry: any, first_time_out: number) => {

if (this.client == null) {
this._pendingQueue = {};
return;
}

this._orders[entry.queue_no] = Object.create({
...entry,
queue_no: entry.queue_no
});
if (this._pendingUpload[entry.path] != null) {
this._pendingUpload[entry.path].cancel();
}

/* Mengikuti kelipatan concurent */
let _debouncePendingOut = first_time_out == null ? (100 * (entry.queue_no == 0 ? 1 : entry.queue_no + 1)) : first_time_out;
this._pendingUpload[entry.path] = debounce(async (entry: any) => {

if (this.client == null) {
return;
}

let deleteQueueFunc = () => {
this._pendingUpload[entry.path] = null;
delete this._pendingUpload[entry.path];
Expand Down
3 changes: 2 additions & 1 deletion src/app/devsync2/services/DevSync2Service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({

/* Restart the syncronize */
if (this.uploader != null) {
this.uploader.clientClose();
this.uploader.onListener('RESTART', {});
this.uploader = null;
}
Expand All @@ -746,7 +747,7 @@ const DevRsyncService = BaseService.extend<DevRsyncServiceInterface>({
process.stdout.write(chalk.green('Remote | ') + 'Restarting...' + '\r');
setTimeout(() => {
this.construct(this._cli);
}, 3000);
}, 1000);
}
var closeRemote = () => {
if (this._currentConf.devsync.script.remote.on_stop != "" && this._currentConf.devsync.script.remote.on_stop != null) {
Expand Down
Loading

0 comments on commit a49cd23

Please sign in to comment.