Initial commit
This commit is contained in:
75
workers/DrvBlastNotifWorker.js
Normal file
75
workers/DrvBlastNotifWorker.js
Normal file
@ -0,0 +1,75 @@
|
||||
const SandboxedJobMQ = require('bullmq').SandboxedJob;
|
||||
const moment = require('moment');
|
||||
const LibWinston = require('../library/LibWinston');
|
||||
const LibFirebase = require('../library/LibFirebase');
|
||||
const DriversModels = require('../models/DriversModels');
|
||||
// const GpsTracksModels = require('../models/GpsTracksModels');
|
||||
|
||||
const schedulerName = process.env.REDIS_SCHEDULER_DRV_BLAST_NOTIF;
|
||||
const Logger = LibWinston.initialize(schedulerName);
|
||||
|
||||
module.exports = async (job) => {
|
||||
try {
|
||||
Logger.log('info', `${schedulerName} running: ${JSON.stringify(job.opts)}`);
|
||||
/**
|
||||
* cek apakah ord_pck_drop.stts(status_delivery) === OrdersPckDropsModels.STTS_DELIVERY_FINISH_PICKUP
|
||||
* jika iya dan sudah upload menu_travel_document maka kendaraan sedang dalam perjalanan ke lokasi drop
|
||||
* cek apakah ord_pck_drop.stts(status_delivery) === OrdersPckDropsModels.STTS_DELIVERY_OTW_DROP
|
||||
* jika iya dan ord_pck_drop.drv_app_lock_menu_otw_drop_at === 0 maka kendaraan masih dalam perjalanan ke lokasi drop
|
||||
*/
|
||||
|
||||
const libFirebase = new LibFirebase();
|
||||
let notifTitle = 'Pengecekan Aplikasi'; // cek app
|
||||
let notifBody = 'Harap Dihiraukan'; // cek app
|
||||
|
||||
// (async function() {
|
||||
try {
|
||||
async function checkNotifNLogs(job) {
|
||||
libFirebase.sendToDevice(job.drv_fcm_token, {
|
||||
// notification: {
|
||||
// title: notifTitle,
|
||||
// body: notifBody,
|
||||
// },
|
||||
data: {
|
||||
title: notifTitle,
|
||||
body: notifBody,
|
||||
type: '' + LibFirebase.blastNotif,
|
||||
detail_id: '',
|
||||
content_available: 'true',
|
||||
}
|
||||
}, {
|
||||
priority: 'high', // to apple: normal(5), high(10)
|
||||
android: {
|
||||
priority: 'high', // to anroid: low(?). normal(5), high(10)
|
||||
},
|
||||
content_available: true,
|
||||
click_action: 'FLUTTER_NOTIFICATION_CLICK',
|
||||
});
|
||||
}
|
||||
|
||||
let loop = process.env.SCHEDULE_DRV_BLAST_NOTIF_MAX_LOOP;
|
||||
for (let x = 0; x < loop; x++) {
|
||||
// all drivers login
|
||||
const allDrvLogins = await DriversModels.getDriversLogin(DriversModels.IS_LOGIN);
|
||||
for (const drv of allDrvLogins) {
|
||||
await checkNotifNLogs({drv_fcm_token: drv.fcm_token});
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
Logger.log('error', `${schedulerName} error: ${JSON.stringify(e)}`);
|
||||
}
|
||||
// })();
|
||||
return {
|
||||
type: 'success',
|
||||
message: 'success run scheduler drv up photo',
|
||||
data: null,
|
||||
};
|
||||
} catch (e) {
|
||||
return {
|
||||
type: 'error',
|
||||
message: e.message,
|
||||
e: e,
|
||||
};
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user