This repository has been archived by the owner on May 1, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
516 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Queue; | ||
|
||
use Queue; | ||
use Error; | ||
|
||
class Controller extends \Kirby\Panel\Controllers\Base | ||
{ | ||
public static function retry($id) | ||
{ | ||
try { | ||
queue::retry($id); | ||
|
||
panel()->notify(':)'); | ||
} catch (Error $e) { | ||
panel()->alert($e->getMessage()); | ||
} | ||
|
||
panel()->redirect(); | ||
} | ||
|
||
public static function remove($id) | ||
{ | ||
try { | ||
queue::remove($id); | ||
|
||
panel()->notify(':)'); | ||
} catch (Error $e) { | ||
panel()->alert($e->getMessage()); | ||
} | ||
|
||
panel()->redirect(); | ||
} | ||
|
||
public static function flush() | ||
{ | ||
queue::flush(); | ||
|
||
panel()->notify(':)'); | ||
|
||
panel()->redirect(); | ||
} | ||
|
||
public static function work() | ||
{ | ||
$count_jobs = queue::jobs()->count(); | ||
|
||
while (queue::hasJobs()) { | ||
queue::work(); | ||
} | ||
|
||
$count_failed = queue::failedJobs()->count(); | ||
|
||
$message = 'Did ' . ($count_jobs == 1 ? '1 job' : $count_jobs . ' jobs'); | ||
|
||
if ($count_failed) { | ||
$message .= ', '; | ||
$message .= ($count_failed == 1 ? '1 job' : $count_failed . ' jobs'); | ||
$message .= ' failed'; | ||
|
||
panel()->alert($message); | ||
} else { | ||
panel()->notify($message); | ||
} | ||
|
||
panel()->redirect(); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
load([ | ||
'queue\\controller' => __DIR__ . DS . 'controller.php' | ||
]); | ||
|
||
$kirby->set('widget', 'failedjobs', __DIR__ . DS . 'widget'); | ||
|
||
panel()->routes([ | ||
[ | ||
'pattern' => 'queue/retry/(:any)', | ||
'filter' => 'auth', | ||
'action' => 'Queue\Controller::retry' | ||
], | ||
[ | ||
'pattern' => 'queue/remove/(:any)', | ||
'filter' => 'auth', | ||
'action' => 'Queue\Controller::remove' | ||
], | ||
[ | ||
'pattern' => 'queue/flush', | ||
'filter' => 'auth', | ||
'action' => 'Queue\Controller::flush' | ||
], | ||
[ | ||
'pattern' => 'queue/work', | ||
'filter' => 'auth', | ||
'action' => 'Queue\Controller::work' | ||
] | ||
]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<style> | ||
.btn-small{ | ||
padding: .2em .75em; | ||
display: block; | ||
margin-bottom: .2em; | ||
} | ||
|
||
.buttons { | ||
position: absolute; | ||
top: 0; | ||
right: .3em; | ||
} | ||
|
||
.normal-white-space { | ||
white-space: normal; | ||
position: relative; | ||
} | ||
</style> | ||
|
||
<div class="dashboard-box"> | ||
<ul class="dashboard-items"> | ||
|
||
<?php foreach ($failed as $job): ?> | ||
|
||
<li class="dashboard-item"> | ||
<figure class="normal-white-space"> | ||
<figcaption class="dashboard-item-text " style=" | ||
width: calc(100% - 3em); | ||
padding-top: 0.5em; | ||
"> | ||
<strong><?= $job->name() ?></strong><br> | ||
<em><?= $job->error() ?></em> | ||
</figcaption> | ||
|
||
<div class="buttons"> | ||
<a class="btn btn-rounded btn-small" | ||
href="<?=url('/panel/queue/retry/'.$job->id()) ?>" target> | ||
<i class="icon fa fa-refresh"></i> | ||
</a> | ||
|
||
<a class="btn btn-rounded btn-negative btn-small" | ||
href="<?=url('/panel/queue/remove/'.$job->id()) ?>" target> | ||
<i class="icon fa fa-remove"></i> | ||
</a> | ||
</div> | ||
</figure> | ||
|
||
|
||
|
||
<div class="dashboard-item-text" style=" | ||
margin: 0.75em; | ||
"> | ||
<?php if (is_array($job->data())) foreach ($job->data() as $key => $value): ?> | ||
<strong><?= $key ?></strong>: <code><?=$value?></code><br> | ||
<?php endforeach ?> | ||
|
||
</div> | ||
</li> | ||
<?php endforeach ?> | ||
|
||
</ul> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
if(!panel()->user()->isAdmin()) return false; | ||
|
||
$jobs_count = queue::jobs()->count(); | ||
|
||
// Don't show the Widget if there are no failed jobs, | ||
// but DO display it if there are more than 5 jobs piled up | ||
// to remind the user there is a queue at all | ||
if(!queue::failedJobs()->count() and $jobs_count < 5) return false; | ||
|
||
return | ||
[ | ||
'title' => [ | ||
'text' => 'Failed jobs', | ||
'compressed' => false | ||
], | ||
'options' => [ | ||
[ | ||
'text' => | ||
($jobs_count == 1 ? '1 job' : $jobs_count . ' jobs') | ||
. ' waiting', | ||
'icon' => 'square-o', | ||
'link' => 'queue/work' | ||
], | ||
[ | ||
'text' => 'Flush all', | ||
'icon' => 'trash-o', | ||
'link' => 'queue/flush' | ||
] | ||
|
||
], | ||
'html' => function() { | ||
$failed = queue::failedJobs(); | ||
|
||
if (!$failed->count()) return 'No failed jobs.'; | ||
|
||
return tpl::load(__DIR__ . DS . 'failedjobs.html.php', compact('failed')); | ||
} | ||
]; |
Oops, something went wrong.