Browse Source

chore(job-queue-plugin): Remove unused code

David Höck 1 year ago
parent
commit
6c97290337

+ 0 - 32
packages/job-queue-plugin/src/bullmq/bullmq-job-queue-strategy.ts

@@ -28,7 +28,6 @@ import { filter, takeUntil } from 'rxjs/operators';
 
 import { ALL_JOB_TYPES, BULLMQ_PLUGIN_OPTIONS, loggerCtx } from './constants';
 import { RedisHealthIndicator } from './redis-health-indicator';
-import { getJobsByTypeScript } from './scripts/get-jobs-by-type';
 import { BullMQPluginOptions } from './types';
 
 const DEFAULT_CONCURRENCY = 3;
@@ -288,37 +287,6 @@ export class BullMQJobQueueStrategy implements InspectableJobQueueStrategy {
 
                 const jobCounts = (await bullQueue?.getJobCounts(...jobTypes)) ?? 0;
                 totalItems = Object.values(jobCounts).reduce((sum, num) => sum + num, 0);
-            } else {
-                const queueNames = Array.from(this.queues.keys()).map(queueName => `bull:${queueName}`);
-
-                const [total, queueNameAndJobIds] = (await this.redisConnection.eval(
-                    getJobsByTypeScript,
-                    queueNames.length,
-                    ...queueNames,
-                    skip,
-                    take,
-                    ...jobTypes,
-                )) as [number, string[]];
-
-                // jobIds are in the format of `bull:vendure-queue-<queue-name>:<job-id>`
-
-                items = (
-                    await Promise.all(
-                        queueNameAndJobIds.map(fqJobId => {
-                            const resolved = this.resolveQueueNameAndJobIdFromRedisKey(fqJobId);
-
-                            if (!resolved) {
-                                return null;
-                            }
-
-                            const bullJobId = this.buildUniqueJobId(resolved.queueName, resolved.jobId);
-
-                            return this.findOneBullJob(bullJobId);
-                        }),
-                    )
-                ).filter(notNullOrUndefined);
-
-                totalItems = total;
             }
         } catch (e: any) {
             throw new InternalServerError(e.message);

+ 0 - 91
packages/job-queue-plugin/src/bullmq/scripts/get-jobs-by-type.ts

@@ -1,91 +0,0 @@
-// language=Lua
-export const getJobsByTypeScript = `
---[[
-  Get paginated job ids across all queues for provided states, including queue name, and return total job count
-  Input:
-    ARGV[1]    start
-    ARGV[2]    end
-    ARGV[3...] states (e.g., "completed", "failed", "active", etc.)
-    KEYS[...]  List of queues
-]]
-
-local start = tonumber(ARGV[1])
-local stop = tonumber(ARGV[2])
-local combinedKey = 'temp:union:all_states'
-
--- Initialize arrays to handle sorted sets and lists
-local setsToUnionize = {}
-local jobIdsWithQueueNames = {}
-
--- Iterate over all queue names (KEYS) and states (ARGV[3..n])
-for i = 1, #KEYS do
-  local queueName = KEYS[i] -- Queue name
-  for j = 3, #ARGV do
-    local state = ARGV[j]
-    local setKey = queueName .. ':' .. state
-    local keyType = redis.call('TYPE', setKey).ok
-
-    -- Handle sorted sets (e.g., completed, failed)
-    if keyType == 'zset' and redis.call('EXISTS', setKey) == 1 then
-      table.insert(setsToUnionize, setKey)
-    end
-
-    -- Handle lists (e.g., wait, active)
-    if keyType == 'list' and redis.call('EXISTS', setKey) == 1 then
-      local listItems = redis.call('LRANGE', setKey, 0, -1)
-      for _, jobId in ipairs(listItems) do
-        -- Append queue name to jobId from lists
-        table.insert(jobIdsWithQueueNames, queueName .. ':' .. jobId)
-      end
-    end
-  end
-end
-
--- If no valid sets or lists were found, return an empty result with total count 0
-if #setsToUnionize == 0 and #jobIdsWithQueueNames == 0 then
-  return {0, {}}
-end
-
--- Union all sorted sets into a temporary sorted set (if there are any sorted sets)
-if #setsToUnionize > 0 then
-  redis.call('ZUNIONSTORE', combinedKey, #setsToUnionize, unpack(setsToUnionize))
-end
-
--- Get job ids from the sorted set (if any) and append the queue name for each job
-if #setsToUnionize > 0 then
-  local jobIdsFromSets = redis.call('ZREVRANGE', combinedKey, 0, -1)
-  for _, jobId in ipairs(jobIdsFromSets) do
-    -- Append queue name to jobId from sorted sets
-    for i = 1, #KEYS do
-      local queueName = KEYS[i]
-      local setKey = queueName .. ':' .. ARGV[3] -- Assuming the same state across all queues
-      if redis.call('ZSCORE', setKey, jobId) then
-        table.insert(jobIdsWithQueueNames, queueName .. ':' .. jobId)
-        break
-      end
-    end
-  end
-end
-
--- Sort all job ids in descending order (to mimic ZREVRANGE behavior)
-table.sort(jobIdsWithQueueNames, function(a, b)
-  local jobIdA = tonumber(a:match(':(%d+)$')) or 0 -- Safely extract and convert job ID to number, fallback to 0
-  local jobIdB = tonumber(b:match(':(%d+)$')) or 0 -- Safely extract and convert job ID to number, fallback to 0
-  return jobIdA > jobIdB
-end)
-
--- Get the total number of jobs
-local totalJobs = #jobIdsWithQueueNames
-
--- Paginate the results
-local paginatedJobIds = {}
-for i = start + 1, math.min(stop + 1, totalJobs) do
-  table.insert(paginatedJobIds, jobIdsWithQueueNames[i])
-end
-
--- Cleanup the temporary sorted set
-redis.call('DEL', combinedKey)
-
--- Return the total job count and the paginated job ids
-return {totalJobs, paginatedJobIds}
-`;