import { DailyStockRunGlobalActionContext } from 'gadget-server';
/**
* @param { DailyStockRunGlobalActionContext } context
*/
export async function run({ params, logger, api, connections }) {
logger.info('Starting dailyStockRun global action');
const activeShops = [];
logger.info('Fetching active and dailyStockRunEnabled Shopify shops');
let shops = await api.shopifyShop.findMany({
first: 250,
filter: {
AND: [{ state: { inState: 'created.installed' } }, { dailyStockRunEnabled: { equals: true } }]
},
select: {
id: true,
domain: true
}
});
activeShops.push(...shops);
while (shops.hasNextPage) {
shops = await shops.nextPage();
activeShops.push(...shops);
}
logger.info(`Found ${activeShops.length} active and dailyStockRunEnabled Shopify shops`);
for (const shop of activeShops) {
logger.info(`Enqueueing dailyStockRun action for shop: ${shop.domain}`);
// Add shop action to queue
await api.enqueue(
api.shopifyShop.dailyStockRun,
{ id: shop.id },
{ maxConcurrency: 1, queue: 'dailyStockRunShop' }
);
}
logger.info('dailyStockRun global action completed successfully');
}
export const options = {
triggers: {
api: true,
scheduler: [{ every: 'day', at: '01:00 UTC' }]
}
};
import { DailyStockRunGlobalActionContext } from 'gadget-server';
/**
* @param { DailyStockRunGlobalActionContext } context
*/
export async function run({ params, logger, api, connections }) {
logger.info('Starting dailyStockRun global action');
const activeShops = [];
logger.info('Fetching active and dailyStockRunEnabled Shopify shops');
let shops = await api.shopifyShop.findMany({
first: 250,
filter: {
AND: [{ state: { inState: 'created.installed' } }, { dailyStockRunEnabled: { equals: true } }]
},
select: {
id: true,
domain: true
}
});
activeShops.push(...shops);
while (shops.hasNextPage) {
shops = await shops.nextPage();
activeShops.push(...shops);
}
logger.info(`Found ${activeShops.length} active and dailyStockRunEnabled Shopify shops`);
for (const shop of activeShops) {
logger.info(`Enqueueing dailyStockRun action for shop: ${shop.domain}`);
// Add shop action to queue
await api.enqueue(
api.shopifyShop.dailyStockRun,
{ id: shop.id },
{ maxConcurrency: 1, queue: 'dailyStockRunShop' }
);
}
logger.info('dailyStockRun global action completed successfully');
}
export const options = {
triggers: {
api: true,
scheduler: [{ every: 'day', at: '01:00 UTC' }]
}
};