parent
3ddcd2d7cb
commit
2dcd95c74b
@ -1,10 +1,22 @@
|
|||||||
extends layouts/main-sidebar
|
extends layouts/main-sidebar
|
||||||
block content
|
block content
|
||||||
|
|
||||||
h1 Sample DTP Web Application
|
|
||||||
p
|
p
|
||||||
img(src="/img/the-bobs.jpg", alt="The Bobs have questions").uk-width-large
|
img(src="/img/the-bobs.jpg", alt="The Bobs have questions").responsive
|
||||||
|
|
||||||
|
h1 Sample DTP Web Application
|
||||||
p This application doesn't actually do anything. The Bobs would have questions.
|
p This application doesn't actually do anything. The Bobs would have questions.
|
||||||
|
|
||||||
pre= JSON.stringify(user, null, 2)
|
if user
|
||||||
|
h2 Current User
|
||||||
|
pre= JSON.stringify(user, null, 2)
|
||||||
|
|
||||||
|
if session
|
||||||
|
h2 Session
|
||||||
|
pre= JSON.stringify(session, null, 2)
|
||||||
|
|
||||||
|
h2 Site Configuration
|
||||||
|
pre= JSON.stringify(config, null, 2)
|
||||||
|
|
||||||
|
h2 Package Information
|
||||||
|
pre= JSON.stringify(pkg, null, 2)
|
@ -0,0 +1,88 @@
|
|||||||
|
// sample-worker.js
|
||||||
|
// Copyright (C) 2022 DTP Technologies, LLC
|
||||||
|
// License: Apache-2.0
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const DTP_COMPONENT = { name: 'Sample Worker', slug: 'sample-worker' };
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
require('dotenv').config({ path: path.resolve(__dirname, '..', '..', '.env') });
|
||||||
|
|
||||||
|
const {
|
||||||
|
SiteLog,
|
||||||
|
SiteWorker,
|
||||||
|
} = require(path.join(__dirname, '..', '..', 'lib', 'site-lib'));
|
||||||
|
|
||||||
|
const { CronJob } = require('cron');
|
||||||
|
|
||||||
|
module.rootPath = path.resolve(__dirname, '..', '..');
|
||||||
|
module.pkg = require(path.resolve(__dirname, '..', '..', 'package.json'));
|
||||||
|
|
||||||
|
module.config = {
|
||||||
|
environment: process.env.NODE_ENV,
|
||||||
|
root: module.rootPath,
|
||||||
|
component: DTP_COMPONENT,
|
||||||
|
};
|
||||||
|
|
||||||
|
module.config.site = require(path.join(module.rootPath, 'config', 'site'));
|
||||||
|
module.config.http = require(path.join(module.rootPath, 'config', 'http'));
|
||||||
|
|
||||||
|
class SampleWorker extends SiteWorker {
|
||||||
|
|
||||||
|
constructor (dtp) {
|
||||||
|
super(dtp, { });
|
||||||
|
}
|
||||||
|
|
||||||
|
async start ( ) {
|
||||||
|
const CRON_TIMEZONE = 'America/New_York';
|
||||||
|
|
||||||
|
await super.start();
|
||||||
|
|
||||||
|
this.log.info('starting worker job');
|
||||||
|
this.job = new CronJob(
|
||||||
|
'*/5 * * * * *',
|
||||||
|
this.runJob.bind(this),
|
||||||
|
null, true, CRON_TIMEZONE,
|
||||||
|
);
|
||||||
|
|
||||||
|
const { jobQueue: jobQueueService } = this.dtp.services;
|
||||||
|
this.sampleJobQueue = jobQueueService.getJobQueue('dtp-sample', this.dtp.config.jobQueues['dtp-sample']);
|
||||||
|
this.sampleJobQueue.process('dtp-sample', 1, this.processDtpSample.bind(this));
|
||||||
|
}
|
||||||
|
|
||||||
|
async stop ( ) {
|
||||||
|
this.log.info('stopping worker job');
|
||||||
|
this.job.stop();
|
||||||
|
delete this.job;
|
||||||
|
}
|
||||||
|
|
||||||
|
async runJob ( ) {
|
||||||
|
this.log.alert('sample job starting');
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Your worker will do interesting things here
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.log.alert('sample job ending');
|
||||||
|
}
|
||||||
|
|
||||||
|
async processDtpSample (job) {
|
||||||
|
this.log.info('received sample job', { id: job.id, data: job.data });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
(async ( ) => {
|
||||||
|
try {
|
||||||
|
module.log = new SiteLog(module, module.config.component);
|
||||||
|
module.worker = new SampleWorker(module);
|
||||||
|
await module.worker.start();
|
||||||
|
} catch (error) {
|
||||||
|
module.log.error('failed to start worker', {
|
||||||
|
component: module.config.component,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
})();
|
@ -0,0 +1,8 @@
|
|||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
scheme: (process.env.NODE_ENV === 'production') ? 'https' : 'http',
|
||||||
|
address: process.env.HTTP_BIND_ADDRESS,
|
||||||
|
port: parseInt(process.env.HTTP_BIND_PORT, 10),
|
||||||
|
};
|
@ -0,0 +1,62 @@
|
|||||||
|
// site-service.js
|
||||||
|
// Copyright (C) 2022 DTP Technologies, LLC
|
||||||
|
// License: Apache-2.0
|
||||||
|
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
const SitePlatform = require(path.join(__dirname, 'site-platform'));
|
||||||
|
const { SiteCommon } = require(path.join(__dirname, 'site-common'));
|
||||||
|
|
||||||
|
class SiteWorker extends SiteCommon {
|
||||||
|
|
||||||
|
constructor (dtp, component) {
|
||||||
|
super(dtp, component);
|
||||||
|
}
|
||||||
|
|
||||||
|
async start ( ) {
|
||||||
|
try {
|
||||||
|
process.on('unhandledRejection', (error, p) => {
|
||||||
|
this.log.error('Unhandled rejection', {
|
||||||
|
error: error,
|
||||||
|
promise: p,
|
||||||
|
stack: error.stack
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
process.on('warning', (error) => {
|
||||||
|
this.log.alert('warning', { error });
|
||||||
|
});
|
||||||
|
|
||||||
|
process.once('SIGINT', async ( ) => {
|
||||||
|
this.log.info('SIGINT received');
|
||||||
|
this.log.info('requesting shutdown...');
|
||||||
|
|
||||||
|
await this.stop();
|
||||||
|
|
||||||
|
const exitCode = await SitePlatform.shutdown();
|
||||||
|
process.nextTick(( ) => {
|
||||||
|
process.exit(exitCode);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Site Platform startup
|
||||||
|
*/
|
||||||
|
await SitePlatform.startPlatform(this.dtp);
|
||||||
|
} catch (error) {
|
||||||
|
this.log.error('failed to start worker', {
|
||||||
|
component: this.dtp.config.component,
|
||||||
|
error,
|
||||||
|
});
|
||||||
|
process.exit(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async stop ( ) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.SiteWorker = SiteWorker;
|
Loading…
Reference in new issue