github.com/wfusion/gofusion@v1.1.14/common/infra/asynq/asynqmon/ui/src/reducers/queuesReducer.ts (about)

     1  import {
     2    GroupsActionTypes,
     3    LIST_GROUPS_SUCCESS,
     4  } from "../actions/groupsActions";
     5  import {
     6    LIST_QUEUES_SUCCESS,
     7    LIST_QUEUES_BEGIN,
     8    QueuesActionTypes,
     9    PAUSE_QUEUE_BEGIN,
    10    PAUSE_QUEUE_SUCCESS,
    11    PAUSE_QUEUE_ERROR,
    12    RESUME_QUEUE_BEGIN,
    13    RESUME_QUEUE_ERROR,
    14    RESUME_QUEUE_SUCCESS,
    15    DELETE_QUEUE_BEGIN,
    16    DELETE_QUEUE_ERROR,
    17    DELETE_QUEUE_SUCCESS,
    18    LIST_QUEUES_ERROR,
    19  } from "../actions/queuesActions";
    20  import {
    21    BATCH_DELETE_ARCHIVED_TASKS_SUCCESS,
    22    BATCH_DELETE_RETRY_TASKS_SUCCESS,
    23    BATCH_DELETE_SCHEDULED_TASKS_SUCCESS,
    24    BATCH_ARCHIVE_RETRY_TASKS_SUCCESS,
    25    BATCH_ARCHIVE_SCHEDULED_TASKS_SUCCESS,
    26    BATCH_RUN_ARCHIVED_TASKS_SUCCESS,
    27    BATCH_RUN_RETRY_TASKS_SUCCESS,
    28    BATCH_RUN_SCHEDULED_TASKS_SUCCESS,
    29    DELETE_ALL_ARCHIVED_TASKS_SUCCESS,
    30    DELETE_ALL_RETRY_TASKS_SUCCESS,
    31    DELETE_ALL_SCHEDULED_TASKS_SUCCESS,
    32    DELETE_ARCHIVED_TASK_SUCCESS,
    33    DELETE_RETRY_TASK_SUCCESS,
    34    DELETE_SCHEDULED_TASK_SUCCESS,
    35    ARCHIVE_ALL_RETRY_TASKS_SUCCESS,
    36    ARCHIVE_ALL_SCHEDULED_TASKS_SUCCESS,
    37    ARCHIVE_RETRY_TASK_SUCCESS,
    38    ARCHIVE_SCHEDULED_TASK_SUCCESS,
    39    LIST_ACTIVE_TASKS_SUCCESS,
    40    LIST_ARCHIVED_TASKS_SUCCESS,
    41    LIST_PENDING_TASKS_SUCCESS,
    42    LIST_RETRY_TASKS_SUCCESS,
    43    LIST_SCHEDULED_TASKS_SUCCESS,
    44    RUN_ALL_ARCHIVED_TASKS_SUCCESS,
    45    RUN_ALL_RETRY_TASKS_SUCCESS,
    46    RUN_ALL_SCHEDULED_TASKS_SUCCESS,
    47    RUN_ARCHIVED_TASK_SUCCESS,
    48    RUN_RETRY_TASK_SUCCESS,
    49    RUN_SCHEDULED_TASK_SUCCESS,
    50    TasksActionTypes,
    51    ARCHIVE_PENDING_TASK_SUCCESS,
    52    DELETE_PENDING_TASK_SUCCESS,
    53    BATCH_ARCHIVE_PENDING_TASKS_SUCCESS,
    54    BATCH_DELETE_PENDING_TASKS_SUCCESS,
    55    ARCHIVE_ALL_PENDING_TASKS_SUCCESS,
    56    DELETE_ALL_PENDING_TASKS_SUCCESS,
    57    DELETE_COMPLETED_TASK_SUCCESS,
    58    DELETE_ALL_COMPLETED_TASKS_SUCCESS,
    59    BATCH_DELETE_COMPLETED_TASKS_SUCCESS,
    60    DELETE_ALL_AGGREGATING_TASKS_SUCCESS,
    61    ARCHIVE_ALL_AGGREGATING_TASKS_SUCCESS,
    62    RUN_ALL_AGGREGATING_TASKS_SUCCESS,
    63    BATCH_DELETE_AGGREGATING_TASKS_SUCCESS,
    64    BATCH_RUN_AGGREGATING_TASKS_SUCCESS,
    65    BATCH_ARCHIVE_AGGREGATING_TASKS_SUCCESS,
    66    DELETE_AGGREGATING_TASK_SUCCESS,
    67    RUN_AGGREGATING_TASK_SUCCESS,
    68    ARCHIVE_AGGREGATING_TASK_SUCCESS,
    69    LIST_AGGREGATING_TASKS_SUCCESS,
    70  } from "../actions/tasksActions";
    71  import { Queue } from "../api";
    72  
    73  interface QueuesState {
    74    loading: boolean;
    75    data: QueueInfo[];
    76    error: string;
    77  }
    78  
    79  export interface QueueInfo {
    80    name: string; // name of the queue.
    81    currentStats: Queue;
    82    requestPending: boolean; // indicates pause/resume/delete action is pending on this queue
    83  }
    84  
    85  const initialState: QueuesState = { data: [], loading: false, error: "" };
    86  
    87  function queuesReducer(
    88    state = initialState,
    89    action: QueuesActionTypes | TasksActionTypes | GroupsActionTypes
    90  ): QueuesState {
    91    switch (action.type) {
    92      case LIST_QUEUES_BEGIN:
    93        return { ...state, loading: true };
    94  
    95      case LIST_QUEUES_SUCCESS:
    96        const { queues } = action.payload;
    97        return {
    98          ...state,
    99          loading: false,
   100          error: "",
   101          data: queues.map((q: Queue) => ({
   102            name: q.queue,
   103            currentStats: q,
   104            requestPending: false,
   105          })),
   106        };
   107  
   108      case LIST_QUEUES_ERROR:
   109        return {
   110          ...state,
   111          loading: false,
   112          error: action.error,
   113        };
   114  
   115      case DELETE_QUEUE_BEGIN:
   116      case PAUSE_QUEUE_BEGIN:
   117      case RESUME_QUEUE_BEGIN: {
   118        const newData = state.data.map((queueInfo) => {
   119          if (queueInfo.name !== action.queue) {
   120            return queueInfo;
   121          }
   122          return { ...queueInfo, requestPending: true };
   123        });
   124        return { ...state, data: newData };
   125      }
   126  
   127      case DELETE_QUEUE_SUCCESS: {
   128        const newData = state.data.filter(
   129          (queueInfo) => queueInfo.name !== action.queue
   130        );
   131        return { ...state, data: newData };
   132      }
   133  
   134      case PAUSE_QUEUE_SUCCESS: {
   135        const newData = state.data.map((queueInfo) => {
   136          if (queueInfo.name !== action.queue) {
   137            return queueInfo;
   138          }
   139          return {
   140            ...queueInfo,
   141            requestPending: false,
   142            currentStats: { ...queueInfo.currentStats, paused: true },
   143          };
   144        });
   145        return { ...state, data: newData };
   146      }
   147  
   148      case RESUME_QUEUE_SUCCESS: {
   149        const newData = state.data.map((queueInfo) => {
   150          if (queueInfo.name !== action.queue) {
   151            return queueInfo;
   152          }
   153          return {
   154            ...queueInfo,
   155            requestPending: false,
   156            currentStats: { ...queueInfo.currentStats, paused: false },
   157          };
   158        });
   159        return { ...state, data: newData };
   160      }
   161  
   162      case DELETE_QUEUE_ERROR:
   163      case PAUSE_QUEUE_ERROR:
   164      case RESUME_QUEUE_ERROR: {
   165        const newData = state.data.map((queueInfo) => {
   166          if (queueInfo.name !== action.queue) {
   167            return queueInfo;
   168          }
   169          return {
   170            ...queueInfo,
   171            requestPending: false,
   172          };
   173        });
   174        return { ...state, data: newData };
   175      }
   176  
   177      case LIST_ACTIVE_TASKS_SUCCESS:
   178      case LIST_PENDING_TASKS_SUCCESS:
   179      case LIST_AGGREGATING_TASKS_SUCCESS:
   180      case LIST_SCHEDULED_TASKS_SUCCESS:
   181      case LIST_RETRY_TASKS_SUCCESS:
   182      case LIST_ARCHIVED_TASKS_SUCCESS: {
   183        const newData = state.data
   184          .filter((queueInfo) => queueInfo.name !== action.queue)
   185          .concat({
   186            name: action.queue,
   187            currentStats: action.payload.stats,
   188            requestPending: false,
   189          });
   190        return { ...state, data: newData };
   191      }
   192  
   193      case RUN_AGGREGATING_TASK_SUCCESS: {
   194        const newData = state.data.map((queueInfo) => {
   195          if (queueInfo.name !== action.queue) {
   196            return queueInfo;
   197          }
   198          return {
   199            ...queueInfo,
   200            currentStats: {
   201              ...queueInfo.currentStats,
   202              pending: queueInfo.currentStats.pending + 1,
   203              aggregating: queueInfo.currentStats.aggregating - 1,
   204            },
   205          };
   206        });
   207        return { ...state, data: newData };
   208      }
   209  
   210      case RUN_SCHEDULED_TASK_SUCCESS: {
   211        const newData = state.data.map((queueInfo) => {
   212          if (queueInfo.name !== action.queue) {
   213            return queueInfo;
   214          }
   215          return {
   216            ...queueInfo,
   217            currentStats: {
   218              ...queueInfo.currentStats,
   219              pending: queueInfo.currentStats.pending + 1,
   220              scheduled: queueInfo.currentStats.scheduled - 1,
   221            },
   222          };
   223        });
   224        return { ...state, data: newData };
   225      }
   226  
   227      case RUN_RETRY_TASK_SUCCESS: {
   228        const newData = state.data.map((queueInfo) => {
   229          if (queueInfo.name !== action.queue) {
   230            return queueInfo;
   231          }
   232          return {
   233            ...queueInfo,
   234            currentStats: {
   235              ...queueInfo.currentStats,
   236              pending: queueInfo.currentStats.pending + 1,
   237              retry: queueInfo.currentStats.retry - 1,
   238            },
   239          };
   240        });
   241        return { ...state, data: newData };
   242      }
   243  
   244      case RUN_ARCHIVED_TASK_SUCCESS: {
   245        const newData = state.data.map((queueInfo) => {
   246          if (queueInfo.name !== action.queue) {
   247            return queueInfo;
   248          }
   249          return {
   250            ...queueInfo,
   251            currentStats: {
   252              ...queueInfo.currentStats,
   253              pending: queueInfo.currentStats.pending + 1,
   254              archived: queueInfo.currentStats.archived - 1,
   255            },
   256          };
   257        });
   258        return { ...state, data: newData };
   259      }
   260  
   261      case ARCHIVE_PENDING_TASK_SUCCESS: {
   262        const newData = state.data.map((queueInfo) => {
   263          if (queueInfo.name !== action.queue) {
   264            return queueInfo;
   265          }
   266          return {
   267            ...queueInfo,
   268            currentStats: {
   269              ...queueInfo.currentStats,
   270              archived: queueInfo.currentStats.archived + 1,
   271              pending: queueInfo.currentStats.pending - 1,
   272            },
   273          };
   274        });
   275        return { ...state, data: newData };
   276      }
   277  
   278      case ARCHIVE_AGGREGATING_TASK_SUCCESS: {
   279        const newData = state.data.map((queueInfo) => {
   280          if (queueInfo.name !== action.queue) {
   281            return queueInfo;
   282          }
   283          return {
   284            ...queueInfo,
   285            currentStats: {
   286              ...queueInfo.currentStats,
   287              archived: queueInfo.currentStats.archived + 1,
   288              aggregating: queueInfo.currentStats.aggregating - 1,
   289            },
   290          };
   291        });
   292        return { ...state, data: newData };
   293      }
   294  
   295      case ARCHIVE_SCHEDULED_TASK_SUCCESS: {
   296        const newData = state.data.map((queueInfo) => {
   297          if (queueInfo.name !== action.queue) {
   298            return queueInfo;
   299          }
   300          return {
   301            ...queueInfo,
   302            currentStats: {
   303              ...queueInfo.currentStats,
   304              archived: queueInfo.currentStats.archived + 1,
   305              scheduled: queueInfo.currentStats.scheduled - 1,
   306            },
   307          };
   308        });
   309        return { ...state, data: newData };
   310      }
   311  
   312      case ARCHIVE_RETRY_TASK_SUCCESS: {
   313        const newData = state.data.map((queueInfo) => {
   314          if (queueInfo.name !== action.queue) {
   315            return queueInfo;
   316          }
   317          return {
   318            ...queueInfo,
   319            currentStats: {
   320              ...queueInfo.currentStats,
   321              archived: queueInfo.currentStats.archived + 1,
   322              retry: queueInfo.currentStats.retry - 1,
   323            },
   324          };
   325        });
   326        return { ...state, data: newData };
   327      }
   328  
   329      case DELETE_PENDING_TASK_SUCCESS: {
   330        const newData = state.data.map((queueInfo) => {
   331          if (queueInfo.name !== action.queue) {
   332            return queueInfo;
   333          }
   334          return {
   335            ...queueInfo,
   336            currentStats: {
   337              ...queueInfo.currentStats,
   338              size: queueInfo.currentStats.size - 1,
   339              pending: queueInfo.currentStats.pending - 1,
   340            },
   341          };
   342        });
   343        return { ...state, data: newData };
   344      }
   345  
   346      case DELETE_SCHEDULED_TASK_SUCCESS: {
   347        const newData = state.data.map((queueInfo) => {
   348          if (queueInfo.name !== action.queue) {
   349            return queueInfo;
   350          }
   351          return {
   352            ...queueInfo,
   353            currentStats: {
   354              ...queueInfo.currentStats,
   355              size: queueInfo.currentStats.size - 1,
   356              scheduled: queueInfo.currentStats.scheduled - 1,
   357            },
   358          };
   359        });
   360        return { ...state, data: newData };
   361      }
   362  
   363      case DELETE_AGGREGATING_TASK_SUCCESS: {
   364        const newData = state.data.map((queueInfo) => {
   365          if (queueInfo.name !== action.queue) {
   366            return queueInfo;
   367          }
   368          return {
   369            ...queueInfo,
   370            currentStats: {
   371              ...queueInfo.currentStats,
   372              size: queueInfo.currentStats.size - 1,
   373              aggregating: queueInfo.currentStats.aggregating - 1,
   374            },
   375          };
   376        });
   377        return { ...state, data: newData };
   378      }
   379  
   380      case BATCH_ARCHIVE_PENDING_TASKS_SUCCESS: {
   381        const newData = state.data.map((queueInfo) => {
   382          if (queueInfo.name !== action.queue) {
   383            return queueInfo;
   384          }
   385          return {
   386            ...queueInfo,
   387            currentStats: {
   388              ...queueInfo.currentStats,
   389              archived:
   390                queueInfo.currentStats.archived +
   391                action.payload.archived_ids.length,
   392              pending:
   393                queueInfo.currentStats.pending -
   394                action.payload.archived_ids.length,
   395            },
   396          };
   397        });
   398        return { ...state, data: newData };
   399      }
   400  
   401      case BATCH_DELETE_PENDING_TASKS_SUCCESS: {
   402        const newData = state.data.map((queueInfo) => {
   403          if (queueInfo.name !== action.queue) {
   404            return queueInfo;
   405          }
   406          return {
   407            ...queueInfo,
   408            currentStats: {
   409              ...queueInfo.currentStats,
   410              size:
   411                queueInfo.currentStats.size - action.payload.deleted_ids.length,
   412              pending:
   413                queueInfo.currentStats.pending -
   414                action.payload.deleted_ids.length,
   415            },
   416          };
   417        });
   418        return { ...state, data: newData };
   419      }
   420  
   421      case ARCHIVE_ALL_PENDING_TASKS_SUCCESS: {
   422        const newData = state.data.map((queueInfo) => {
   423          if (queueInfo.name !== action.queue) {
   424            return queueInfo;
   425          }
   426          return {
   427            ...queueInfo,
   428            currentStats: {
   429              ...queueInfo.currentStats,
   430              archived:
   431                queueInfo.currentStats.archived + queueInfo.currentStats.pending,
   432              pending: 0,
   433            },
   434          };
   435        });
   436        return { ...state, data: newData };
   437      }
   438  
   439      case ARCHIVE_ALL_AGGREGATING_TASKS_SUCCESS: {
   440        const newData = state.data.map((queueInfo) => {
   441          if (queueInfo.name !== action.queue) {
   442            return queueInfo;
   443          }
   444          return {
   445            ...queueInfo,
   446            currentStats: {
   447              ...queueInfo.currentStats,
   448              groups: queueInfo.currentStats.groups - 1,
   449              archived: queueInfo.currentStats.archived + action.archived,
   450              aggregating: queueInfo.currentStats.aggregating - action.archived,
   451            },
   452          };
   453        });
   454        return { ...state, data: newData };
   455      }
   456  
   457      case DELETE_ALL_PENDING_TASKS_SUCCESS: {
   458        const newData = state.data.map((queueInfo) => {
   459          if (queueInfo.name !== action.queue) {
   460            return queueInfo;
   461          }
   462          return {
   463            ...queueInfo,
   464            currentStats: {
   465              ...queueInfo.currentStats,
   466              size: queueInfo.currentStats.size - action.deleted,
   467              pending: 0,
   468            },
   469          };
   470        });
   471        return { ...state, data: newData };
   472      }
   473  
   474      case BATCH_RUN_SCHEDULED_TASKS_SUCCESS: {
   475        const newData = state.data.map((queueInfo) => {
   476          if (queueInfo.name !== action.queue) {
   477            return queueInfo;
   478          }
   479          return {
   480            ...queueInfo,
   481            currentStats: {
   482              ...queueInfo.currentStats,
   483              pending:
   484                queueInfo.currentStats.pending +
   485                action.payload.pending_ids.length,
   486              scheduled:
   487                queueInfo.currentStats.scheduled -
   488                action.payload.pending_ids.length,
   489            },
   490          };
   491        });
   492        return { ...state, data: newData };
   493      }
   494  
   495      case BATCH_ARCHIVE_SCHEDULED_TASKS_SUCCESS: {
   496        const newData = state.data.map((queueInfo) => {
   497          if (queueInfo.name !== action.queue) {
   498            return queueInfo;
   499          }
   500          return {
   501            ...queueInfo,
   502            currentStats: {
   503              ...queueInfo.currentStats,
   504              archived:
   505                queueInfo.currentStats.archived +
   506                action.payload.archived_ids.length,
   507              scheduled:
   508                queueInfo.currentStats.scheduled -
   509                action.payload.archived_ids.length,
   510            },
   511          };
   512        });
   513        return { ...state, data: newData };
   514      }
   515  
   516      case BATCH_DELETE_SCHEDULED_TASKS_SUCCESS: {
   517        const newData = state.data.map((queueInfo) => {
   518          if (queueInfo.name !== action.queue) {
   519            return queueInfo;
   520          }
   521          return {
   522            ...queueInfo,
   523            currentStats: {
   524              ...queueInfo.currentStats,
   525              size:
   526                queueInfo.currentStats.size - action.payload.deleted_ids.length,
   527              scheduled:
   528                queueInfo.currentStats.scheduled -
   529                action.payload.deleted_ids.length,
   530            },
   531          };
   532        });
   533        return { ...state, data: newData };
   534      }
   535  
   536      case RUN_ALL_AGGREGATING_TASKS_SUCCESS: {
   537        const newData = state.data.map((queueInfo) => {
   538          if (queueInfo.name !== action.queue) {
   539            return queueInfo;
   540          }
   541          return {
   542            ...queueInfo,
   543            currentStats: {
   544              ...queueInfo.currentStats,
   545              groups: queueInfo.currentStats.groups - 1,
   546              pending: queueInfo.currentStats.pending + action.scheduled,
   547              aggregating: queueInfo.currentStats.aggregating - action.scheduled,
   548            },
   549          };
   550        });
   551        return { ...state, data: newData };
   552      }
   553  
   554      case RUN_ALL_SCHEDULED_TASKS_SUCCESS: {
   555        const newData = state.data.map((queueInfo) => {
   556          if (queueInfo.name !== action.queue) {
   557            return queueInfo;
   558          }
   559          return {
   560            ...queueInfo,
   561            currentStats: {
   562              ...queueInfo.currentStats,
   563              pending:
   564                queueInfo.currentStats.pending + queueInfo.currentStats.scheduled,
   565              scheduled: 0,
   566            },
   567          };
   568        });
   569        return { ...state, data: newData };
   570      }
   571  
   572      case ARCHIVE_ALL_SCHEDULED_TASKS_SUCCESS: {
   573        const newData = state.data.map((queueInfo) => {
   574          if (queueInfo.name !== action.queue) {
   575            return queueInfo;
   576          }
   577          return {
   578            ...queueInfo,
   579            currentStats: {
   580              ...queueInfo.currentStats,
   581              archived:
   582                queueInfo.currentStats.archived +
   583                queueInfo.currentStats.scheduled,
   584              scheduled: 0,
   585            },
   586          };
   587        });
   588        return { ...state, data: newData };
   589      }
   590  
   591      case DELETE_ALL_AGGREGATING_TASKS_SUCCESS: {
   592        const newData = state.data.map((queueInfo) => {
   593          if (queueInfo.name !== action.queue) {
   594            return queueInfo;
   595          }
   596          return {
   597            ...queueInfo,
   598            currentStats: {
   599              ...queueInfo.currentStats,
   600              size: queueInfo.currentStats.size - action.deleted,
   601              groups: queueInfo.currentStats.groups - 1,
   602              aggregating: queueInfo.currentStats.aggregating - action.deleted,
   603            },
   604          };
   605        });
   606        return { ...state, data: newData };
   607      }
   608  
   609      case DELETE_ALL_SCHEDULED_TASKS_SUCCESS: {
   610        const newData = state.data.map((queueInfo) => {
   611          if (queueInfo.name !== action.queue) {
   612            return queueInfo;
   613          }
   614          return {
   615            ...queueInfo,
   616            currentStats: {
   617              ...queueInfo.currentStats,
   618              size: queueInfo.currentStats.size - action.deleted,
   619              scheduled: 0,
   620            },
   621          };
   622        });
   623        return { ...state, data: newData };
   624      }
   625  
   626      case DELETE_RETRY_TASK_SUCCESS: {
   627        const newData = state.data.map((queueInfo) => {
   628          if (queueInfo.name !== action.queue) {
   629            return queueInfo;
   630          }
   631          return {
   632            ...queueInfo,
   633            currentStats: {
   634              ...queueInfo.currentStats,
   635              size: queueInfo.currentStats.size - 1,
   636              retry: queueInfo.currentStats.retry - 1,
   637            },
   638          };
   639        });
   640        return { ...state, data: newData };
   641      }
   642  
   643      case BATCH_RUN_RETRY_TASKS_SUCCESS: {
   644        const newData = state.data.map((queueInfo) => {
   645          if (queueInfo.name !== action.queue) {
   646            return queueInfo;
   647          }
   648          return {
   649            ...queueInfo,
   650            currentStats: {
   651              ...queueInfo.currentStats,
   652              pending:
   653                queueInfo.currentStats.pending +
   654                action.payload.pending_ids.length,
   655              retry:
   656                queueInfo.currentStats.retry - action.payload.pending_ids.length,
   657            },
   658          };
   659        });
   660        return { ...state, data: newData };
   661      }
   662  
   663      case BATCH_ARCHIVE_RETRY_TASKS_SUCCESS: {
   664        const newData = state.data.map((queueInfo) => {
   665          if (queueInfo.name !== action.queue) {
   666            return queueInfo;
   667          }
   668          return {
   669            ...queueInfo,
   670            currentStats: {
   671              ...queueInfo.currentStats,
   672              archived:
   673                queueInfo.currentStats.pending +
   674                action.payload.archived_ids.length,
   675              retry:
   676                queueInfo.currentStats.retry - action.payload.archived_ids.length,
   677            },
   678          };
   679        });
   680        return { ...state, data: newData };
   681      }
   682  
   683      case BATCH_DELETE_RETRY_TASKS_SUCCESS: {
   684        const newData = state.data.map((queueInfo) => {
   685          if (queueInfo.name !== action.queue) {
   686            return queueInfo;
   687          }
   688          return {
   689            ...queueInfo,
   690            currentStats: {
   691              ...queueInfo.currentStats,
   692              size:
   693                queueInfo.currentStats.size - action.payload.deleted_ids.length,
   694              retry:
   695                queueInfo.currentStats.retry - action.payload.deleted_ids.length,
   696            },
   697          };
   698        });
   699        return { ...state, data: newData };
   700      }
   701  
   702      case BATCH_RUN_AGGREGATING_TASKS_SUCCESS: {
   703        const newData = state.data.map((queueInfo) => {
   704          if (queueInfo.name !== action.queue) {
   705            return queueInfo;
   706          }
   707          return {
   708            ...queueInfo,
   709            currentStats: {
   710              ...queueInfo.currentStats,
   711              pending:
   712                queueInfo.currentStats.pending +
   713                action.payload.pending_ids.length,
   714              aggregating:
   715                queueInfo.currentStats.aggregating -
   716                action.payload.pending_ids.length,
   717            },
   718          };
   719        });
   720        return { ...state, data: newData };
   721      }
   722  
   723      case BATCH_ARCHIVE_AGGREGATING_TASKS_SUCCESS: {
   724        const newData = state.data.map((queueInfo) => {
   725          if (queueInfo.name !== action.queue) {
   726            return queueInfo;
   727          }
   728          return {
   729            ...queueInfo,
   730            currentStats: {
   731              ...queueInfo.currentStats,
   732              archived:
   733                queueInfo.currentStats.archived +
   734                action.payload.archived_ids.length,
   735              aggregating:
   736                queueInfo.currentStats.aggregating -
   737                action.payload.archived_ids.length,
   738            },
   739          };
   740        });
   741        return { ...state, data: newData };
   742      }
   743  
   744      case BATCH_DELETE_AGGREGATING_TASKS_SUCCESS: {
   745        const newData = state.data.map((queueInfo) => {
   746          if (queueInfo.name !== action.queue) {
   747            return queueInfo;
   748          }
   749          return {
   750            ...queueInfo,
   751            currentStats: {
   752              ...queueInfo.currentStats,
   753              size:
   754                queueInfo.currentStats.size - action.payload.deleted_ids.length,
   755              aggregating:
   756                queueInfo.currentStats.aggregating -
   757                action.payload.deleted_ids.length,
   758            },
   759          };
   760        });
   761        return { ...state, data: newData };
   762      }
   763  
   764      case RUN_ALL_RETRY_TASKS_SUCCESS: {
   765        const newData = state.data.map((queueInfo) => {
   766          if (queueInfo.name !== action.queue) {
   767            return queueInfo;
   768          }
   769          return {
   770            ...queueInfo,
   771            currentStats: {
   772              ...queueInfo.currentStats,
   773              pending:
   774                queueInfo.currentStats.pending + queueInfo.currentStats.retry,
   775              retry: 0,
   776            },
   777          };
   778        });
   779        return { ...state, data: newData };
   780      }
   781  
   782      case ARCHIVE_ALL_RETRY_TASKS_SUCCESS: {
   783        const newData = state.data.map((queueInfo) => {
   784          if (queueInfo.name !== action.queue) {
   785            return queueInfo;
   786          }
   787          return {
   788            ...queueInfo,
   789            currentStats: {
   790              ...queueInfo.currentStats,
   791              archived:
   792                queueInfo.currentStats.archived + queueInfo.currentStats.retry,
   793              retry: 0,
   794            },
   795          };
   796        });
   797        return { ...state, data: newData };
   798      }
   799  
   800      case DELETE_ALL_RETRY_TASKS_SUCCESS: {
   801        const newData = state.data.map((queueInfo) => {
   802          if (queueInfo.name !== action.queue) {
   803            return queueInfo;
   804          }
   805          return {
   806            ...queueInfo,
   807            currentStats: {
   808              ...queueInfo.currentStats,
   809              size: queueInfo.currentStats.size - action.deleted,
   810              retry: 0,
   811            },
   812          };
   813        });
   814        return { ...state, data: newData };
   815      }
   816  
   817      case DELETE_ARCHIVED_TASK_SUCCESS: {
   818        const newData = state.data.map((queueInfo) => {
   819          if (queueInfo.name !== action.queue) {
   820            return queueInfo;
   821          }
   822          return {
   823            ...queueInfo,
   824            currentStats: {
   825              ...queueInfo.currentStats,
   826              size: queueInfo.currentStats.size - 1,
   827              archived: queueInfo.currentStats.archived - 1,
   828            },
   829          };
   830        });
   831        return { ...state, data: newData };
   832      }
   833  
   834      case DELETE_COMPLETED_TASK_SUCCESS: {
   835        const newData = state.data.map((queueInfo) => {
   836          if (queueInfo.name !== action.queue) {
   837            return queueInfo;
   838          }
   839          return {
   840            ...queueInfo,
   841            currentStats: {
   842              ...queueInfo.currentStats,
   843              size: queueInfo.currentStats.size - 1,
   844              completed: queueInfo.currentStats.completed - 1,
   845            },
   846          };
   847        });
   848        return { ...state, data: newData };
   849      }
   850  
   851      case BATCH_RUN_ARCHIVED_TASKS_SUCCESS: {
   852        const newData = state.data.map((queueInfo) => {
   853          if (queueInfo.name !== action.queue) {
   854            return queueInfo;
   855          }
   856          return {
   857            ...queueInfo,
   858            currentStats: {
   859              ...queueInfo.currentStats,
   860              pending:
   861                queueInfo.currentStats.pending +
   862                action.payload.pending_ids.length,
   863              archived:
   864                queueInfo.currentStats.archived -
   865                action.payload.pending_ids.length,
   866            },
   867          };
   868        });
   869        return { ...state, data: newData };
   870      }
   871  
   872      case BATCH_DELETE_ARCHIVED_TASKS_SUCCESS: {
   873        const newData = state.data.map((queueInfo) => {
   874          if (queueInfo.name !== action.queue) {
   875            return queueInfo;
   876          }
   877          return {
   878            ...queueInfo,
   879            currentStats: {
   880              ...queueInfo.currentStats,
   881              size:
   882                queueInfo.currentStats.size - action.payload.deleted_ids.length,
   883              archived:
   884                queueInfo.currentStats.archived -
   885                action.payload.deleted_ids.length,
   886            },
   887          };
   888        });
   889        return { ...state, data: newData };
   890      }
   891  
   892      case BATCH_DELETE_COMPLETED_TASKS_SUCCESS: {
   893        const newData = state.data.map((queueInfo) => {
   894          if (queueInfo.name !== action.queue) {
   895            return queueInfo;
   896          }
   897          return {
   898            ...queueInfo,
   899            currentStats: {
   900              ...queueInfo.currentStats,
   901              size:
   902                queueInfo.currentStats.size - action.payload.deleted_ids.length,
   903              completed:
   904                queueInfo.currentStats.completed -
   905                action.payload.deleted_ids.length,
   906            },
   907          };
   908        });
   909        return { ...state, data: newData };
   910      }
   911  
   912      case RUN_ALL_ARCHIVED_TASKS_SUCCESS: {
   913        const newData = state.data.map((queueInfo) => {
   914          if (queueInfo.name !== action.queue) {
   915            return queueInfo;
   916          }
   917          return {
   918            ...queueInfo,
   919            currentStats: {
   920              ...queueInfo.currentStats,
   921              pending:
   922                queueInfo.currentStats.pending + queueInfo.currentStats.archived,
   923              archived: 0,
   924            },
   925          };
   926        });
   927        return { ...state, data: newData };
   928      }
   929  
   930      case DELETE_ALL_ARCHIVED_TASKS_SUCCESS: {
   931        const newData = state.data.map((queueInfo) => {
   932          if (queueInfo.name !== action.queue) {
   933            return queueInfo;
   934          }
   935          return {
   936            ...queueInfo,
   937            currentStats: {
   938              ...queueInfo.currentStats,
   939              size: queueInfo.currentStats.size - action.deleted,
   940              archived: 0,
   941            },
   942          };
   943        });
   944        return { ...state, data: newData };
   945      }
   946  
   947      case DELETE_ALL_COMPLETED_TASKS_SUCCESS: {
   948        const newData = state.data.map((queueInfo) => {
   949          if (queueInfo.name !== action.queue) {
   950            return queueInfo;
   951          }
   952          return {
   953            ...queueInfo,
   954            currentStats: {
   955              ...queueInfo.currentStats,
   956              size: queueInfo.currentStats.size - action.deleted,
   957              completed: 0,
   958            },
   959          };
   960        });
   961        return { ...state, data: newData };
   962      }
   963  
   964      case LIST_GROUPS_SUCCESS: {
   965        const newData = state.data.map((queueInfo) => {
   966          if (queueInfo.name !== action.queue) {
   967            return queueInfo;
   968          }
   969          return {
   970            ...queueInfo,
   971            currentStats: action.payload.stats,
   972          };
   973        });
   974        return { ...state, data: newData };
   975      }
   976  
   977      default:
   978        return state;
   979    }
   980  }
   981  
   982  export default queuesReducer;