Skip to content

Commit

Permalink
Sync: Added and improved env sync flags.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascallapointe committed Feb 18, 2023
1 parent 2bc3606 commit 32013a8
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
5 changes: 5 additions & 0 deletions .env.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ PORT=3000
DOMAIN=my.domain.com
ALLOWED_ORIGIN=api.pasklab.com

### APP
SKIP_INTEGRITY_CHECK=yes
SKIP_INIT_SYNC=yes
SKIP_SYNC=yes

### API
BLOCKFROST_API_KEY=mainnety0GVPWFAKEdSTiJ3WVGhi
FIXERIO_API_KEY=5d49deaceddFAKEe52eeb4239c
Expand Down
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,26 @@ Not implemented yet.

#### TypeORM

To prevent production data lost, database schema synchronization is disable
To prevent production data lost, database schema synchronization is disabled
by default. To enable entities **auto-synchronization**, set the node environment to the following:

```bash
NODE_ENV=development
```

#### Integrity Check

Integrity check is skipped when env `SKIP_INTEGRITY_CHECK` have the string value `yes`. String value is used instead of
boolean for **dotenv** compatibility.

#### Data Sync

Initial sync is skipped when env `SKIP_INIT_SYNC` have the string value `yes`. String value is used instead of
boolean for **dotenv** compatibility.

Data Sync at startup or scheduled cronjob is skipped when env `SKIP_SYNC` have the string value `yes`. String value is used instead of
boolean for **dotenv** compatibility.

## TypeORM CLI

Since he TypeORM cli cannot read from the Nest app configuration, it requires a datasource file named `typeOrm.config.ts` located at the project root.
Expand Down
28 changes: 19 additions & 9 deletions src/sync/sync.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { PoolService } from '../pool/pool.service';
import { AccountService } from '../account/account.service';
import { PoolCertService } from '../pool/pool-cert.service';
import { Account } from '../account/entities/account.entity';
import * as process from 'process';

@Injectable()
export class SyncService {
Expand All @@ -26,16 +27,25 @@ export class SyncService {
private readonly poolCertService: PoolCertService,
private readonly accountService: AccountService,
) {
if (!process.env.SKIP_SYNC) {
this.init().then();
}
this.init().then();
}

async init(): Promise<void> {
await this.integrityCheck();
this.logger.log('Init sync data ...');
await this.spotSyncService.init();
this.sync().then();
if (process.env.SKIP_INTEGRITY_CHECK === 'yes') {
this.logger.warn(
'SKIP_INTEGRITY_CHECK enabled, skipping integrity checks ...',
);
} else {
await this.integrityCheck();
}

if (process.env.SKIP_INIT_SYNC === 'yes') {
this.logger.warn('SKIP_INIT_SYNC enabled, skipping initial sync ...');
} else {
this.logger.log('Init sync data ...');
await this.spotSyncService.init();
this.sync().then();
}
}

private async integrityCheck(): Promise<void> {
Expand All @@ -45,8 +55,8 @@ export class SyncService {

@Cron('0 20 * * *', { name: 'Daily Sync', timeZone: 'America/Toronto' })
private async sync(): Promise<void> {
if (process.env.SKIP_SYNC) {
this.logger.log('SKIP_SYNC enabled, skipping daily sync ...');
if (process.env.SKIP_SYNC === 'yes') {
this.logger.warn('SKIP_SYNC enabled, skipping daily sync ...');
return;
}

Expand Down

0 comments on commit 32013a8

Please sign in to comment.