Skip to content

Commit

Permalink
feat: queue improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
SychO9 committed Dec 8, 2023
1 parent 0bc859e commit 82b7fa1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,15 @@ export default class QueueSection extends Component<{}> {
{
label: extractText(app.translator.trans('flarum-package-manager.admin.sections.queue.columns.status')),
content: (task) => (
<Label
className="PackageManager-queueTable-status"
type={{ running: 'neutral', failure: 'error', pending: 'warning', success: 'success' }[task.status()]}
>
{app.translator.trans(`flarum-package-manager.admin.sections.queue.statuses.${task.status()}`)}
</Label>
<>
<Label
className="PackageManager-queueTable-status"
type={{ running: 'neutral', failure: 'error', pending: 'warning', success: 'success' }[task.status()]}
>
{app.translator.trans(`flarum-package-manager.admin.sections.queue.statuses.${task.status()}`)}
</Label>
{['pending', 'running'].includes(task.status()) && <LoadingIndicator size="small" display="inline" />}
</>
),
},
70
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ export default class SettingsPage extends ExtensionPage {

items.add('control', <ControlSection />, 8);

if (parseInt(app.data.settings['flarum-package-manager.queue_jobs'])) {
if (app.data.settings['flarum-package-manager.queue_jobs'] !== '0' && app.data.settings['flarum-package-manager.queue_jobs']) {
items.add('queue', <QueueSection />, 5);
}

items.setPriority('permissions', 0);

return items;
}

onsaved() {
super.onsaved();
m.redraw();
}
}
27 changes: 27 additions & 0 deletions extensions/package-manager/js/src/admin/utils/jumpToQueue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,36 @@ window.jumpToQueue = jumpToQueue;

export default function jumpToQueue(): void {
app.modal.close();

m.route.set(app.route('extension', { id: 'flarum-package-manager' }));

app.packageManager.queue.load();

setTimeout(() => {
document.getElementById('PackageManager-queueSection')?.scrollIntoView({ block: 'nearest' });
}, 200);

pollQueue();
}

let queuePolling: any = null;

export function pollQueue(): void {
if (queuePolling) {
clearInterval(queuePolling);
}

queuePolling = setTimeout(() => {
app.packageManager.queue.load();

// Check if there is a pending or running task
const task = app.packageManager.queue.getItems()?.find((task) => task.status() === 'pending' || task.status() === 'running');

if (task) {
pollQueue();
} else {
// Refresh the page
window.location.reload();
}
}, 6000);
}
1 change: 1 addition & 0 deletions extensions/package-manager/less/admin/QueueSection.less
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

.Label {
text-transform: uppercase;
margin-inline-end: 8px;
}

.Table {
Expand Down
4 changes: 2 additions & 2 deletions extensions/package-manager/src/Job/ComposerCommandJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ public function __construct(AbstractActionCommand $command, string $phpVersion)
public function handle(Dispatcher $bus)
{
try {
ComposerAdapter::setPhpVersion($this->phpVersion);

$this->command->task->start();

ComposerAdapter::setPhpVersion($this->phpVersion);

$bus->dispatch($this->command);

$this->command->task->end(true);
Expand Down
12 changes: 12 additions & 0 deletions extensions/package-manager/src/Task/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,18 @@ class Task extends AbstractModel
'finished_at' => 'datetime',
];

public static function boot()
{
parent::boot();

static::created(function (self $task) {
// auto clear tasks older than 2 weeks.
static::query()
->where('created_at', '<', Carbon::now()->subWeeks(2))
->delete();
});
}

public static function build(string $operation, ?string $package): self
{
$task = new static;
Expand Down

0 comments on commit 82b7fa1

Please sign in to comment.