Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
JZhang502 committed Jun 6, 2024
2 parents 2d94869 + c990d37 commit 40a1cf1
Show file tree
Hide file tree
Showing 22 changed files with 285 additions and 53 deletions.
30 changes: 30 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
### [4.4.1](https://github.com/bee-queue/arena/compare/v4.4.0...v4.4.1) (2024-05-07)

### Bug Fixes

- **jobs:** validate jobs length in bulk action ([#676](https://github.com/bee-queue/arena/issues/676)) ([2bce363](https://github.com/bee-queue/arena/commit/2bce36391052d747c01aa20adda28d38d4a8fdee))

## [4.4.0](https://github.com/bee-queue/arena/compare/v4.3.0...v4.4.0) (2024-05-03)

### Features

- **bull:** add clean jobs button for completed and failed ([#675](https://github.com/bee-queue/arena/issues/675)) ([e62aef0](https://github.com/bee-queue/arena/commit/e62aef022cf771b715cf65d100391f6f88c5cfd5))

## [4.3.0](https://github.com/bee-queue/arena/compare/v4.2.0...v4.3.0) (2024-04-27)

### Features

- **details:** update job data ([#674](https://github.com/bee-queue/arena/issues/674)) ([24ab67f](https://github.com/bee-queue/arena/commit/24ab67f637da2ae8add30231340e413342de8461))

## [4.2.0](https://github.com/bee-queue/arena/compare/v4.1.1...v4.2.0) (2024-02-12)

### Features

- **add-job:** provide editor for adding options ([#670](https://github.com/bee-queue/arena/issues/670)) ([3f4c640](https://github.com/bee-queue/arena/commit/3f4c6400b090b64fbcec87df03442bb8c2672790))

### [4.1.1](https://github.com/bee-queue/arena/compare/v4.1.0...v4.1.1) (2024-02-08)

### Bug Fixes

- **layouts:** include favicon at layout template ([#668](https://github.com/bee-queue/arena/issues/668)) ([a107ad9](https://github.com/bee-queue/arena/commit/a107ad9b16fb8b5c20abece0ed36ca3855895e41))

## [4.1.0](https://github.com/bee-queue/arena/compare/v4.0.1...v4.1.0) (2023-10-28)

### Features
Expand Down
7 changes: 7 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: '3.2'
services:
redis:
image: redis:6-alpine
container_name: redis-6
ports:
- 6379:6379
2 changes: 1 addition & 1 deletion example/bee.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ async function main() {
.delayUntil(Date.now() + 60 * 1000)
.save();

const job = await queue.createJob({}).save();
await queue.createJob({}).save();

Arena(
{
Expand Down
34 changes: 29 additions & 5 deletions example/bull.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const express = require('express');
const IORedis = require('ioredis');
const path = require('path');
const Arena = require('../');
const Bull = require('bull');
Expand All @@ -8,7 +9,19 @@ const HTTP_SERVER_PORT = 4735;
const REDIS_SERVER_PORT = 6379;

async function main() {
const queue = new Bull('name_of_my_queue', {
const queueName1 = 'name_of_my_queue_1';
const connection = new IORedis({port: REDIS_SERVER_PORT});

const createClient = (type) => {
switch (type) {
case 'client':
return connection;
default:
return new IORedis({port: REDIS_SERVER_PORT});
}
};

const queue = new Bull(queueName1, {
redis: {
port: REDIS_SERVER_PORT,
},
Expand All @@ -26,7 +39,7 @@ async function main() {
}
});

await queue.add({});
await queue.add({data: 'data'});

// adding delayed jobs
const delayedJob = await queue.add({}, {delay: 60 * 1000});
Expand All @@ -42,17 +55,28 @@ async function main() {
queues: [
{
// Required for each queue definition.
name: 'name_of_my_queue',
name: queueName1,

// User-readable display name for the host. Required.
hostId: 'Queue Server 1',

// Queue type (Bull or Bee - default Bull).
type: 'bull',

createClient,
},
{
// Required for each queue definition.
name: 'name_of_my_queue_2',

// User-readable display name for the host. Required.
hostId: 'Queue Server 2',

// Queue type (Bull or Bee - default Bull).
type: 'bull',

redis: {
// host: 'localhost',
port: REDIS_SERVER_PORT,
createClient,
},
},
],
Expand Down
8 changes: 4 additions & 4 deletions example/bullmq.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const Arena = require('../');
const IORedis = require('ioredis');
const {Queue, Worker, FlowProducer} = require('bullmq');

// Select ports that are unlikely to be used by other services a developer might be running locally.
Expand All @@ -9,6 +10,8 @@ async function main() {
const queueName = 'name_of_my_queue';
const parentQueueName = 'name_of_my_parent_queue';

const connection = new IORedis({port: REDIS_SERVER_PORT});

const queue = new Queue(queueName, {
connection: {port: REDIS_SERVER_PORT},
});
Expand Down Expand Up @@ -87,10 +90,7 @@ async function main() {
// Queue type (Bull or Bullmq or Bee - default Bull).
type: 'bullmq',

redis: {
// host: 'localhost',
port: REDIS_SERVER_PORT,
},
redis: connection,
},
{
// Required for each queue definition.
Expand Down
2 changes: 1 addition & 1 deletion example/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"dependencies": {
"@fastify/express": "^2.3.0",
"bee-queue": "^1.4.0",
"bull": "^3.22.6",
"bull": "^4.12.2",
"bullmq": "^4.8.0",
"express": "^4.17.1",
"fastify": "^4.13.0"
Expand Down
4 changes: 2 additions & 2 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 @@ -40,6 +40,8 @@
"ci": "npm run lint && if [ -z \"$CI\" ]; then npm run ci:commitlint; fi",
"ci:commitlint": "commitlint --from \"origin/${GITHUB_BASE_REF:-master}\"",
"cm": "git cz",
"dc:up": "docker-compose -f docker-compose.yml up -d",
"dc:down": "docker-compose -f docker-compose.yml down",
"dry:run": "npm publish --dry-run",
"lint": "prettier -c .",
"lint:staged": "lint-staged",
Expand All @@ -66,5 +68,5 @@
"bullmq"
],
"repository": "https://github.com/bee-queue/arena.git",
"version": "4.1.0"
"version": "4.4.1"
}
110 changes: 83 additions & 27 deletions public/dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,38 +210,60 @@ $(document).ready(() => {
queueState,
};

$bulkActionContainer.each((index, value) => {
const isChecked = $(value).find('[name=jobChecked]').is(':checked');
const id = encodeURIComponent($(value).find('[name=jobId]').val());
if (action !== 'clean') {
$bulkActionContainer.each((index, value) => {
const isChecked = $(value).find('[name=jobChecked]').is(':checked');
const id = encodeURIComponent($(value).find('[name=jobId]').val());

if (isChecked) {
data.jobs.push(id);
}
});
}

if (isChecked) {
data.jobs.push(id);
}
});
const count = action === 'clean' ? 1000 : data.jobs.length;

const r = window.confirm(
`${capitalize(action)} ${data.jobs.length} ${
data.jobs.length > 1 ? 'jobs' : 'job'
`${capitalize(action)} ${count} ${
count > 1 ? 'jobs' : 'job'
} in queue "${queueHost}/${queueName}"?`
);
if (r) {
$.ajax({
method: action === 'remove' ? 'POST' : 'PATCH',
url: `${basePath}/api/queue/${encodeURIComponent(
queueHost
)}/${encodeURIComponent(queueName)}/${
action === 'promote' ? 'delayed/' : ''
}job/bulk`,
data: JSON.stringify(data),
contentType: 'application/json',
})
.done(() => {
window.location.reload();
if (action === 'clean') {
$.ajax({
method: 'DELETE',
url: `${basePath}/api/queue/${encodeURIComponent(
queueHost
)}/${encodeURIComponent(queueName)}/jobs/bulk`,
data: JSON.stringify(data),
contentType: 'application/json',
})
.fail((jqXHR) => {
window.alert(`Request failed, check console for error.`);
console.error(jqXHR.responseText);
});
.done(() => {
window.location.reload();
})
.fail((jqXHR) => {
window.alert(`Request failed, check console for error.`);
console.error(jqXHR.responseText);
});
} else {
$.ajax({
method: action === 'remove' ? 'POST' : 'PATCH',
url: `${basePath}/api/queue/${encodeURIComponent(
queueHost
)}/${encodeURIComponent(queueName)}/${
action === 'promote' ? 'delayed/' : ''
}job/bulk`,
data: JSON.stringify(data),
contentType: 'application/json',
})
.done(() => {
window.location.reload();
})
.fail((jqXHR) => {
window.alert(`Request failed, check console for error.`);
console.error(jqXHR.responseText);
});
}
} else {
$(this).prop('disabled', false);
}
Expand All @@ -256,8 +278,9 @@ $(document).ready(() => {

const job = localStorage.getItem('arena:savedJob');
if (job) {
const {name, data} = JSON.parse(job);
const {name, data, opts} = JSON.parse(job);
window.jsonEditor.set(data);
if (window.jsonEditorOpts) window.jsonEditorOpts.set(opts);
$('input.js-add-job-name').val(name);
} else {
window.jsonEditor.set({id: ''});
Expand Down Expand Up @@ -291,7 +314,8 @@ $(document).ready(() => {
$('.js-add-job').on('click', function () {
const name = $('input.js-add-job-name').val() || null;
const data = window.jsonEditor.get();
const job = JSON.stringify({name, data});
const opts = window.jsonEditorOpts ? window.jsonEditorOpts.get() : {};
const job = JSON.stringify({name, data, opts});
localStorage.setItem('arena:savedJob', job);
const {queueHost, queueName} = window.arenaInitialPayload;
$.ajax({
Expand All @@ -312,6 +336,38 @@ $(document).ready(() => {
});
});

$('.js-update-job-data').on('click', function (e) {
e.preventDefault();
const jobId = $(this).data('job-id');
const queueName = $(this).data('queue-name');
const queueHost = $(this).data('queue-host');
const stringifiedData = JSON.stringify(window.jsonEditor.get());
const r = window.confirm(
`Update job #${jobId} data in queue "${queueHost}/${queueName}"?`
);

if (r) {
$.ajax({
url: `${basePath}/api/queue/${encodeURIComponent(
queueHost
)}/${encodeURIComponent(queueName)}/job/${encodeURIComponent(
jobId
)}/data`,
type: 'PUT',
data: stringifiedData,
contentType: 'application/json',
})
.done(() => {
alert('Job data successfully updated!');
window.location.reload();
})
.fail((jqXHR) => {
window.alert('Failed to update job data, check console for error.');
console.error(jqXHR.responseText);
});
}
});

$('.js-add-flow').on('click', function () {
const data = window.jsonEditor.get();
const flow = JSON.stringify({data});
Expand Down
7 changes: 3 additions & 4 deletions src/server/queue/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,6 @@ class Queues {
queue = new Bee(name, options);
queue.IS_BEE = true;
} else if (isBullMQ) {
if (queueConfig.createClient)
options.createClient = queueConfig.createClient;

const {BullMQ} = this._config;
const {redis, ...rest} = options;
queue = new BullMQ(name, {
Expand Down Expand Up @@ -143,14 +140,16 @@ class Queues {
* @param {Object} queue A bee or bull queue class
* @param {Object} data The data to be used within the job
* @param {String} name The name of the Bull job (optional)
* @param {Object} opts The opts to be used within the job
*/
async set(queue, data, name) {
async set(queue, data, name, opts) {
if (queue.IS_BEE) {
return queue.createJob(data).save();
} else {
const args = [
data,
{
...opts,
removeOnComplete: false,
removeOnFail: false,
},
Expand Down
7 changes: 5 additions & 2 deletions src/server/views/api/bulkAction.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const _ = require('lodash');

const ACTIONS = ['remove', 'retry', 'promote'];
const ACTIONS = ['clean', 'remove', 'retry', 'promote'];

function bulkAction(action) {
return async function handler(req, res) {
Expand All @@ -19,7 +19,7 @@ function bulkAction(action) {
const {jobs, queueState} = req.body;

try {
if (!_.isEmpty(jobs)) {
if (!_.isEmpty(jobs) && jobs.length > 0) {
const jobsPromises = jobs.map((id) =>
queue.getJob(decodeURIComponent(id))
);
Expand All @@ -39,6 +39,9 @@ function bulkAction(action) {
: fetchedJobs.map((job) => job[action]());
await Promise.all(actionPromises);
return res.sendStatus(200);
} else if (action === 'clean') {
await queue.clean(1000, queueState);
return res.sendStatus(200);
}
} catch (e) {
const body = {
Expand Down
3 changes: 3 additions & 0 deletions src/server/views/api/bulkJobsClean.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const bulkAction = require('./bulkAction');

module.exports = bulkAction('clean');
Loading

0 comments on commit 40a1cf1

Please sign in to comment.