The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/models/server/raw/OmnichannelQueue.ts

97 lines
1.4 KiB

/* eslint-disable @typescript-eslint/explicit-function-return-type */
import { BaseRaw } from './BaseRaw';
import { IOmnichannelQueueStatus } from '../../../../definition/IOmnichannel';
const UNIQUE_QUEUE_ID = 'queue';
export class OmnichannelQueueRaw extends BaseRaw<IOmnichannelQueueStatus> {
initQueue() {
return this.col.updateOne(
{
_id: UNIQUE_QUEUE_ID,
},
{
$unset: {
stoppedAt: 1,
},
$set: {
startedAt: new Date(),
locked: false,
},
},
{
upsert: true,
},
);
}
stopQueue() {
return this.col.updateOne(
{
_id: UNIQUE_QUEUE_ID,
},
{
$set: {
stoppedAt: new Date(),
locked: false,
},
},
);
}
async lockQueue() {
const date = new Date();
const result = await this.col.findOneAndUpdate(
{
_id: UNIQUE_QUEUE_ID,
$or: [
{
locked: true,
lockedAt: {
$lte: new Date(date.getTime() - 5000),
},
},
{
locked: false,
},
],
},
{
$set: {
locked: true,
// apply 5 secs lock lifetime
lockedAt: new Date(),
},
},
{
sort: {
_id: 1,
},
},
);
return result.value;
}
async unlockQueue() {
const result = await this.col.findOneAndUpdate(
{
_id: UNIQUE_QUEUE_ID,
},
{
$set: {
locked: false,
},
$unset: {
lockedAt: 1,
},
},
{
sort: {
_id: 1,
},
},
);
return result.value;
}
}