psdev-task-manager 1.1.7 → 1.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,30 @@
1
+ name: Update Sites After Release Main
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ workflow_dispatch:
8
+
9
+ permissions:
10
+ contents: write
11
+ packages: write
12
+
13
+ jobs:
14
+ update-sites:
15
+ uses: psdevteamenterprise/ci-workflows/.github/workflows/update-and-notify.yml@main
16
+ with:
17
+ npm_packages_to_update: "[{repo: 'Hisense-Wix/velo-npm'}]"
18
+ sites_to_update: "[{repo: 'psdevteamenterprise/external-template', secret: 'WIX_SR_API_KEY'},
19
+ {repo: 'psdevteamenterprise/internal', secret: 'WIX_SR_API_KEY'},
20
+ {repo: 'psdevteamenterprise/tests-site', secret: 'WIX_PS_API_KEY'},
21
+ {repo: 'psdevteamenterprise/hisense_mexico', secret: 'WIX_HM_API_KEY'},
22
+ ]"
23
+ secrets:
24
+ GH_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
25
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISH }}
26
+ GH_APP_ID: ${{ secrets.GH_APP_ID }}
27
+ GH_APP_PRIVATE_KEY: ${{ secrets.GH_APP_PRIVATE_KEY }}
28
+ WIX_SR_API_KEY: ${{secrets.WIX_SR_API_KEY}}
29
+ WIX_PS_API_KEY: ${{secrets.WIX_PS_API_KEY}}
30
+ WIX_HM_API_KEY: ${{secrets.WIX_HM_API_KEY}}
@@ -75,8 +75,9 @@ function taskManager() {
75
75
  }
76
76
  const isFailedAfterAllRetries = amountOfRetries >= TASK_MAX_TRIES;
77
77
  if (isFailedAfterAllRetries) {
78
+
78
79
  //Only throw error if task is permanently failed, otherwise we have retry mechanism
79
- throw new Error(errMsg);
80
+ throw new Error("task failed after all retries: " + errMsg);
80
81
  }
81
82
  }
82
83
  },
@@ -122,7 +123,6 @@ function taskManager() {
122
123
  try {
123
124
  const scheduledTasks = await getScheduledTasks();
124
125
  console.log(`runScheduledTasks: scheduledTasks count: ${scheduledTasks.length}`);
125
- console.log(`runScheduledTasks: tasksConfig: ${JSON.stringify(tasksConfig)}`);
126
126
  if (scheduledTasks.length) {
127
127
  await processTasksBasedOnVeloLimit(scheduledTasks, tasksConfig);
128
128
  } else {
@@ -2,7 +2,7 @@ const { COLLECTIONS, COLLECTIONS_FIELDS } = require('../../public/consts'); // n
2
2
  const { wixData, wixCollections } = require('../elevated-modules');
3
3
 
4
4
  const { TASK_STATUS, TASK_TYPE, TASK_MAX_TRIES } = require('./consts');
5
-
5
+ const { getAllItems } = require('../utils');
6
6
  /**
7
7
  * Generic function to create a collection if it doesn't exist
8
8
  * @param {string} collectionId - The ID of the collection to create
@@ -168,9 +168,6 @@ const isParentTask = (task, taskConfig) => {
168
168
  return true;
169
169
  };
170
170
  const filterScheduledTasksByStatus = (tasks, tasksConfig) => {
171
- console.log(
172
- `filterScheduledTasksByStatus: tasks count: ${tasks.length} tasksConfig: ${JSON.stringify(tasksConfig)}`
173
- );
174
171
  const shouldIncludeTask = (task, taskConfig) => {
175
172
  console.log(`filterScheduledTasksByStatus: task: ${JSON.stringify(task)}`);
176
173
  console.log(`filterScheduledTasksByStatus: taskConfig: ${JSON.stringify(taskConfig)}`);
@@ -195,6 +192,18 @@ const filterScheduledTasksByStatus = (tasks, tasksConfig) => {
195
192
  console.log(`filterScheduledTasksByStatus: filtered count: ${filtered.length}`);
196
193
  return filtered;
197
194
  };
195
+ const queryAllItems = async query => {
196
+ console.log('start query');
197
+ let oldResults = await query.find();
198
+ console.log(`found items: ${oldResults.items.length}`);
199
+ const allItems = oldResults.items;
200
+ while (oldResults.hasNext()) {
201
+ oldResults = await oldResults.next();
202
+ allItems.push(...oldResults.items);
203
+ }
204
+ console.log(`all items count : ${allItems.length}`);
205
+ return allItems;
206
+ };
198
207
  const getScheduledTasks = async () => {
199
208
  try {
200
209
  const baseQuery = wixData.query(COLLECTIONS.TASKS);
@@ -204,13 +213,12 @@ const getScheduledTasks = async () => {
204
213
  const eventBasedTasksQuery = baseQuery
205
214
  .eq('type', TASK_TYPE.EVENT)
206
215
  .eq('status', TASK_STATUS.FAILED);
207
- return await scheduledTasksQuery
216
+ const toRunQuery = scheduledTasksQuery
208
217
  .or(eventBasedTasksQuery)
209
218
  .lt('amountOfRetries', TASK_MAX_TRIES)
210
219
  .ascending('_updatedDate')
211
- .limit(1000)
212
- .find()
213
- .then(result => result.items);
220
+ .limit(1000);
221
+ return await queryAllItems(toRunQuery);
214
222
  } catch (error) {
215
223
  throw new Error(`[getScheduledTasks] failed with error: ${error.message}`);
216
224
  }
@@ -240,13 +248,11 @@ const getTasksToProcess = ({ scheduledTasks, tasksConfig, maxDuration }) => {
240
248
  });
241
249
  const tasksToProcess = [];
242
250
  let totalDuration = 0;
243
- console.log(`tasksConfig is : ${JSON.stringify(tasksConfig)}`);
244
251
  const filteredScheduledTasks = filterScheduledTasksByStatus(scheduledTasks, tasksConfig);
245
252
  console.log(`filteredScheduledTasks count : ${filteredScheduledTasks.length}`);
246
253
  for (const task of filteredScheduledTasks) {
247
254
  console.log(`task is : ${JSON.stringify(task)}`);
248
255
  const taskConfig = getTaskConfig(task.name, tasksConfig);
249
- console.log(`taskConfig is : ${JSON.stringify(taskConfig)}`);
250
256
  const estimated = taskConfig?.estimatedDurationSec;
251
257
  if (!estimated) {
252
258
  const errMsg = `[getTasksToProcess] estimatedDurationSec is not defined for task ${task.name}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "psdev-task-manager",
3
- "version": "1.1.7",
3
+ "version": "1.1.9",
4
4
  "description": "Task manager library",
5
5
  "keywords": [
6
6
  "task-manager"