Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 uid=33(www-data) gid=33(www-data) groups=33(www-data) Safe-mode: OFF (not secure) /var/www/html/beximco/mrp_process/ drwxr-xr-x | |
| Viewing file: Select action/file-type: var cron = require("node-cron");
const axios = require("axios");
const token =
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6NCwiaWF0IjoxNjYyNTQ1NjY3LCJleHAiOjE5NzgxMjE2Njd9.5lVlCpiqLqBmdASH-06JubosdJ4jmHwqkepXIkaGr3E";
cron.schedule("*/10 * * * * *", async () => {
console.log("running a task every 5 seconds");
var device = await axios.get(
"http://127.0.0.1:1337/machines?machine_id=200001&status=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(device.data.length);
if (device.data.length === 1) {
console.log("SCANNING BEAM");
await updateCron();
}
});
cron.schedule("*/10 * * * * *", async () => {
console.log("running a task every 30 seconds");
var device = await axios.get(
"http://127.0.0.1:1337/machines?machine_id=200003&status=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(device.data.length);
if (device.data.length === 1) {
console.log("UPDATING BEAM");
await updateBeam();
await updateSBeam();
}
});
cron.schedule("*/15 * * * * *", async () => {
console.log("running a task every 30 seconds");
var device = await axios.get(
"http://127.0.0.1:1337/machines?machine_id=200005&status=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(device.data.length);
if (device.data.length === 1) {
console.log("UPDATING WEALING LOOM");
await updateWeavingLoom();
}
});
cron.schedule("*/15 * * * * *", async () => {
console.log("running a task every 30 seconds");
var device = await axios.get(
"http://127.0.0.1:1337/machines?machine_id=200007&status=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(device.data.length);
if (device.data.length === 1) {
console.log("UPDATING FABRIC INSPECTION");
await updateFabricInspection();
}
});
cron.schedule("*/5 * * * * *", async () => {
console.log("running a task every 30 seconds");
var device = await axios.get(
"http://127.0.0.1:1337/machines?machine_id=200009&status=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(device.data.length);
if (device.data.length === 1) {
console.log("UPDATING SEINGING");
await updateSingeing();
}
});
cron.schedule("*/5 * * * * *", async () => {
console.log("running a task every 30 seconds");
var device = await axios.get(
"http://127.0.0.1:1337/machines?machine_id=200009&status=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
console.log(device.data.length);
if (device.data.length === 1) {
console.log("UPDATING SEINGING");
await updateFinishingRolls();
}
});
async function updateCron() {
var cronlogs = await axios.get(
"http://127.0.0.1:1337/equipments?serial_no=1111111115&_sort=id:DESC&_limit=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (cronlogs.data.length === 1) {
console.log("IN LEN");
if (cronlogs.data[0].status == 0) {
console.log("IN STATUS");
const logsBody = {
machine_type: "creel",
machine_id: "200001",
equipment_id: "1111111115",
equipment_type: "warped_beam",
order_id: cronlogs.data[0].order_id,
stage: "stage 1",
factory_id: cronlogs.data[0].factory_id,
process_name: "creeling",
input: "yarn_bags",
output: "beam",
status: 1,
};
await axios.post("http://127.0.0.1:1337/queue", logsBody, {
headers: {
Authorization: "Bearer " + token,
},
});
await axios.put(
"http://127.0.0.1:1337/equipments/" + cronlogs.data[0].id,
{
status: 1,
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
}
async function updateWeavingLoom() {
var queuelogs = await axios.get(
"http://127.0.0.1:1337/queue?status=0&stage=stage 3&equipment_type=sizing_beam",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (queuelogs.data.length > 0) {
console.log("IN LEN");
const element = queuelogs.data[0];
console.log("IN STATUS");
await axios.put(
"http://127.0.0.1:1337/queue/" + element.id,
{
status: 1,
machine_id: "200005",
machine_type: "weaving_loom",
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
async function updateFabricInspection() {
var queuelogs = await axios.get(
"http://127.0.0.1:1337/queue?status=0&stage=stage 4&equipment_type=gray_fabric",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (queuelogs.data.length > 0) {
console.log("IN LEN");
const element = queuelogs.data[0];
console.log("IN STATUS");
await axios.put(
"http://127.0.0.1:1337/queue/" + element.id,
{
status: 1,
machine_id: "200007",
machine_type: "fabric_inspection",
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
async function updateBeam() {
var queuelogs = await axios.get(
"http://127.0.0.1:1337/queue?status=0&stage=stage 2&equipment_type=warped_beam",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (queuelogs.data.length > 0) {
console.log("IN LEN");
for (let index = 0; index < queuelogs.data.length; index++) {
const element = queuelogs.data[index];
console.log("IN STATUS");
await axios.put(
"http://127.0.0.1:1337/queue/" + element.id,
{
status: 1,
machine_id: "200003",
machine_type: "warped_beam_creel",
output_id: "44440",
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
}
async function updateSBeam() {
var cronlogs = await axios.get(
"http://127.0.0.1:1337/equipments?serial_no=44440&_sort=id:DESC&_limit=1",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (cronlogs.data.length === 1) {
console.log("IN LEN");
if (cronlogs.data[0].status == 0) {
console.log("IN STATUS");
// const logsBody = {
// machine_type: "warped_beam_creel",
// machine_id: "200003",
// equipment_id: "44440",
// equipment_type: "sizing_beam",
// order_id: cronlogs.data[0].order_id,
// stage: "stage 2",
// status: 1,
// factory_id: cronlogs.data[0].factory_id,
// process_name: "slasher_dying",
// input: "warped_beam",
// output: "sizing_beam",
// };
// await axios.post("http://127.0.0.1:1337/queue", logsBody, {
// headers: {
// Authorization: "Bearer " + token,
// },
// });
await axios.put(
"http://127.0.0.1:1337/equipments/" + cronlogs.data[0].id,
{
status: 1,
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
}
async function updateSingeing() {
var queuelogs = await axios.get(
"http://127.0.0.1:1337/queue?status=0&stage=stage 5&equipment_type=inspected_gray_fabric",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (queuelogs.data.length > 0) {
console.log("IN LEN");
for (let index = 0; index < queuelogs.data.length; index++) {
const element = queuelogs.data[index];
console.log("IN STATUS");
await axios.put(
"http://127.0.0.1:1337/queue/" + element.id,
{
status: 1,
machine_id: "200009",
machine_type: "singeing",
output_id: "33333330",
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
}
async function updateFinishingRolls() {
var queuelogs = await axios.get(
"http://127.0.0.1:1337/queue?status=0&stage=stage 6&equipment_type=sizing_beam",
{
headers: {
Authorization: "Bearer " + token,
},
}
);
if (queuelogs.data.length > 0) {
console.log("IN LEN");
const element = queuelogs.data[0];
console.log("IN STATUS");
await axios.put(
"http://127.0.0.1:1337/queue/" + element.id,
{
status: 1,
},
{
headers: {
Authorization: "Bearer " + token,
},
}
);
}
}
|
:: Command execute :: | |
--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0079 ]-- |