Kaynağa Gözat

push 26

master
jefry 4 yıl önce
ebeveyn
işleme
6329553719
3 değiştirilmiş dosya ile 49 ekleme ve 18 silme
  1. +6
    -5
      api/message/models/message.settings.json
  2. +10
    -1
      api/message/services/message.js
  3. +33
    -12
      config/functions/cron.js

+ 6
- 5
api/message/models/message.settings.json Dosyayı Görüntüle

@@ -11,11 +11,6 @@
"draftAndPublish": true
},
"attributes": {
"send_from": {
"type": "string",
"regex": "\\+?([ -]?\\d+)+|\\(\\d+\\)([ -]\\d+)",
"required": true
},
"send_to": {
"type": "string",
"regex": "\\+?([ -]?\\d+)+|\\(\\d+\\)([ -]\\d+)",
@@ -42,6 +37,12 @@
"state": {
"type": "string",
"private": false
},
"raw_text": {
"type": "string"
},
"session_datum_key": {
"model": "session-data"
}
}
}

+ 10
- 1
api/message/services/message.js Dosyayı Görüntüle

@@ -5,4 +5,13 @@
* to customize this service
*/

module.exports = {};
module.exports = {
distinctbyKey: async (params) =>{
const results = await strapi.query('message').find(params);
let arrKeys = [];
results.forEach((i)=>{
if(!arrKeys.includes(i["session_datum_key"])) arrKeys.push(i["session_datum_key"]);
});
return arrKeys
}
};

+ 33
- 12
config/functions/cron.js Dosyayı Görüntüle

@@ -1,5 +1,6 @@
"use strict";

const messageModel = require("../../model/messageModel");
const { parseMultipartData, sanitizeEntity } = require("strapi-utils");
/**
* Cron config that gives you an opportunity
* to run scheduled jobs.
@@ -9,21 +10,41 @@
*
* See more details here: https://strapi.io/documentation/developer-docs/latest/concepts/configurations.html#cron-tasks
*/
let clients = {};
module.exports = {
"*/3 * * * * *": async () => {
const draftArticleToPublish = await strapi.api.message.services.message.find(
"*/10 * * * * *": async () => {
const session_key = await strapi.api.message.services.message.distinctbyKey(
{
_sort: "send_from:desc",
_sort: "session_datum_key:desc",
state: "QUEUE",
}
);

draftArticleToPublish.forEach(async (message) => {
await strapi.api.message.services.message.update(
{ id: message.id },
{ state: "SENT" }
);
});
session_key.forEach(async (i)=>{
if(!Object.keys(clients).includes(`${i["id"]}`)){
clients[i["id"]] = null;
messageModel.loadClient(i["session_data"],async (data)=>{
var json = JSON.parse(data);
if (json["STATUS"] == 1 && json["TYPE"] == "READY") {
return clients[i["id"]] = json["DATA"];
}
else if(json["STATUS"] ==0){
return;
}
});
}
})
console.log(clients);
// const messages = await strapi.api.message.services.message.find(
// {
// _sort: "session_datum_key:desc",
// state: "QUEUE",
// }
// );
// messages.forEach(async (message) => {
// await strapi.api.message.services.message.update(
// { id: message.id },
// { state: "SENT" }
// );
// });
},
};

Yükleniyor…
İptal
Kaydet