Skip to content
This repository has been archived by the owner on Oct 30, 2023. It is now read-only.

Commit

Permalink
started-worker-from-uploader-service
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitam747 committed May 22, 2018
1 parent 26d39a9 commit c09f493
Show file tree
Hide file tree
Showing 4 changed files with 171 additions and 27 deletions.
2 changes: 1 addition & 1 deletion config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module.exports = {
"rethinkdb": {
"host": process.env.RDB_HOST,
"port": process.env.RDB_PORT,
"db": "prosync"
"db": "FlowzDBETL"
},
"qOptions": {
"name": "product_sync_worker",
Expand Down
108 changes: 83 additions & 25 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let asi_pass = process.env.asi_password
let sageAccId = process.env.sageAccId
let sageLoginId = process.env.sageLoginId
let sagePwd = process.env.sagePwd

let uploaderService = process.env.uploaderService
// var mongodb = require('mongodb');
// var elasticsearch = require('elasticsearch');
// var MongoClient = require('mongodb').MongoClient;
Expand All @@ -28,13 +28,15 @@ const qOptions = app.qOptions
const q = new Queue(cxnOptions, qOptions)


let serviceUrl = 'http://localhost:3030';
// let uploaderServices = 'http://localhost:3040';
let pdmUrl = 'http://api.flowzcluster.tk/pdmnew/pdm'
let asiUrl = 'https://sandbox-productservice.asicentral.com/api/v4/'
let sageUrl = 'https://www.promoplace.com/ws/ws.dll/XMLDataStream'

// let lookup = 'https://sandbox-productservice.asicentral.com/api/v4/lookup/categorieslist'
let psyncUrl = serviceUrl + '/onlysync'
let psyncUrl = uploaderService + '/product-sync'

const no_image_path = 'https://res.cloudinary.com/flowz/image/upload/v1526652106/builder/gxycflqvc1m23qqknch9.png'

let lookupData = {};

Expand All @@ -56,7 +58,7 @@ async function getAPI(id) {
return resp.data
}).catch(err => {
return {}
})
})
return res;
}

Expand Down Expand Up @@ -547,29 +549,85 @@ function asiProductMap(asi_product, _pdmProduct) {


// ****************** Set Images
asi_product.Images.push({
// ImageURL: pdmProduct.default_image,
ImageURL: 'https://res.cloudinary.com/flowz/raw/upload/v1525085146/product_images/f9ea80ee-6329-48de-b247-a029e1cd841a/54694-blue_1.jpg',
Rank: 1,
IsPrimary: true,
Configurations: [
{
Criteria: 'Product Color',
Value: [
pdmProduct.default_color
]
// asi_product.Images.push({
// // ImageURL: pdmProduct.default_image,
// ImageURL: 'https://res.cloudinary.com/flowz/raw/upload/v1525085146/product_images/f9ea80ee-6329-48de-b247-a029e1cd841a/54694-blue_1.jpg',
// Rank: 1,
// IsPrimary: true,
// Configurations: [
// {
// Criteria: 'Product Color',
// Value: [
// pdmProduct.default_color
// ]
// }
// ]
// })
if (!pdmProduct.hasOwnProperty('images')) {
asi_product.Images.push({
ImageURL: no_image_path,
Rank: 1,
IsPrimary: true,
Configurations: [
{
Criteria: 'Product Color',
Value: [
pdmProduct.default_color
]
}
]
})
} else {
let imagename = pdmProduct.default_image;
let checkArr = [];
for (let item of pdmProduct.images) {
for (let inneritem of item.images) {
let _a = imagename.match('/'+inneritem.web_image+'/g')
if (_a != null) {
checkArr.push(inneritem)
}
}
]
})
}
if (checkArr.length > 0) {
asi_product.Images.push({
ImageURL: checkArr[0].secure_url,
Rank: 1,
IsPrimary: true,
Configurations: [
{
Criteria: 'Product Color',
Value: [
pdmProduct.default_color
]
}
]
})
} else {
asi_product.Images.push({
ImageURL: no_image_path,
Rank: 1,
IsPrimary: true,
Configurations: [
{
Criteria: 'Product Color',
Value: [
pdmProduct.default_color
]
}
]
})
}
}

let rank = 2;
if (pdmProduct.hasOwnProperty('pdmProduct')) {
if (pdmProduct.hasOwnProperty('images')) {
for (let item of pdmProduct.images) {
if (item.hasOwnProperty('images')) {
for (let inneritem of item.images) {
let exist = _.findIndex(asi_product.Images, {ImageURL: inneritem.web_image});
if (exist == -1) {
asi_product.Images.push({
ImageURL: 'https://res.cloudinary.com/flowz/raw/upload/v1525085146/product_images/f9ea80ee-6329-48de-b247-a029e1cd841a/54694-blue_1.jpg',
ImageURL: inneritem.secure_url,
// ImageURL: inneritem.web_image,
Rank: rank,
IsPrimary: false,
Expand Down Expand Up @@ -1039,7 +1097,7 @@ async function syncAsiFunction(vid,skip,syncId) {
console.log('map_product >>>>>>>>>>>>>>>>>>> Update :: ', map_product.SKU);

let update_product = await postASIProduct(aToken, map_product)
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', update_product, '\n UPDATE:: ', JSON.stringify(map_product) + '\n')
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%', update_product + '\n')

let updated_counted = await updateProductProcessed(syncId,count)
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Update', update_product)
Expand All @@ -1052,7 +1110,7 @@ async function syncAsiFunction(vid,skip,syncId) {
console.log('map_product >>>>>>>>>>>>>>>>>>> New :: ', map_product.SKU)
let update_product = await postASIProduct(aToken, map_product)
// console.log('+++++++++++++++++++++++++++++++++ New', update_product)
console.log('+++++++++++++++++++++++++++++++++', update_product, '\n DATA::', JSON.stringify(map_product) + '\n')
console.log('+++++++++++++++++++++++++++++++++', update_product + '\n')

let updated_counted = await updateProductProcessed(syncId,count)
}
Expand Down Expand Up @@ -1090,12 +1148,12 @@ async function syncSageFunction(vid,skip,syncId) {

console.log('xmlproduct ======>', xmlProduct)

let update_product = await postSageProduct(xmlProduct)
console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% update product %%%%%%%%%%%%%%%%%%%%%%%%%%%', update_product)
// let update_product = await postSageProduct(xmlProduct)
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% update product %%%%%%%%%%%%%%%%%%%%%%%%%%%', update_product)

let updated_counted = await updateProductProcessed(syncId,count)
// let updated_counted = await updateProductProcessed(syncId,count)

// count ++
// // count ++
}

}
Expand Down
84 changes: 84 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"asyncawait": "^1.0.6",
"axios": "^0.18.0",
"lodash": "^4.17.10",
"moment": "^2.22.1",
"pino": "^4.16.1",
"rethinkdb-job-queue": "^3.1.7"
"rethinkdb-job-queue": "^3.1.7",
"xml2json": "^0.11.2"
}
}

0 comments on commit c09f493

Please sign in to comment.