mirror of
https://github.com/hibiken/asynqmon.git
synced 2025-01-19 03:05:53 +08:00
Adjust payload field to print content if bytes are printable
This commit is contained in:
parent
b5de7e6994
commit
d58d549d4c
@ -2,6 +2,8 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"time"
|
"time"
|
||||||
|
"unicode"
|
||||||
|
"unicode/utf8"
|
||||||
|
|
||||||
"github.com/hibiken/asynq"
|
"github.com/hibiken/asynq"
|
||||||
)
|
)
|
||||||
@ -86,7 +88,7 @@ func toDailyStatsList(in []*asynq.DailyStats) []*DailyStats {
|
|||||||
type BaseTask struct {
|
type BaseTask struct {
|
||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Type string `json:"type"`
|
Type string `json:"type"`
|
||||||
Payload []byte `json:"payload"`
|
Payload string `json:"payload"`
|
||||||
Queue string `json:"queue"`
|
Queue string `json:"queue"`
|
||||||
MaxRetry int `json:"max_retry"`
|
MaxRetry int `json:"max_retry"`
|
||||||
Retried int `json:"retried"`
|
Retried int `json:"retried"`
|
||||||
@ -114,7 +116,7 @@ func toActiveTask(t *asynq.TaskInfo) *ActiveTask {
|
|||||||
base := &BaseTask{
|
base := &BaseTask{
|
||||||
ID: t.ID(),
|
ID: t.ID(),
|
||||||
Type: t.Type(),
|
Type: t.Type(),
|
||||||
Payload: t.Payload(),
|
Payload: toPrintablePayload(t.Payload()),
|
||||||
Queue: t.Queue(),
|
Queue: t.Queue(),
|
||||||
MaxRetry: t.MaxRetry(),
|
MaxRetry: t.MaxRetry(),
|
||||||
Retried: t.Retried(),
|
Retried: t.Retried(),
|
||||||
@ -140,7 +142,7 @@ func toPendingTask(t *asynq.TaskInfo) *PendingTask {
|
|||||||
base := &BaseTask{
|
base := &BaseTask{
|
||||||
ID: t.ID(),
|
ID: t.ID(),
|
||||||
Type: t.Type(),
|
Type: t.Type(),
|
||||||
Payload: t.Payload(),
|
Payload: toPrintablePayload(t.Payload()),
|
||||||
Queue: t.Queue(),
|
Queue: t.Queue(),
|
||||||
MaxRetry: t.MaxRetry(),
|
MaxRetry: t.MaxRetry(),
|
||||||
Retried: t.Retried(),
|
Retried: t.Retried(),
|
||||||
@ -164,11 +166,31 @@ type ScheduledTask struct {
|
|||||||
NextProcessAt time.Time `json:"next_process_at"`
|
NextProcessAt time.Time `json:"next_process_at"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// isPrintable reports whether the given data is comprised of all printable runes.
|
||||||
|
func isPrintable(data []byte) bool {
|
||||||
|
if !utf8.Valid(data) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
for _, r := range string(data) {
|
||||||
|
if !unicode.IsPrint(r) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func toPrintablePayload(payload []byte) string {
|
||||||
|
if !isPrintable(payload) {
|
||||||
|
return "non-printable bytes"
|
||||||
|
}
|
||||||
|
return string(payload)
|
||||||
|
}
|
||||||
|
|
||||||
func toScheduledTask(t *asynq.TaskInfo) *ScheduledTask {
|
func toScheduledTask(t *asynq.TaskInfo) *ScheduledTask {
|
||||||
base := &BaseTask{
|
base := &BaseTask{
|
||||||
ID: t.ID(),
|
ID: t.ID(),
|
||||||
Type: t.Type(),
|
Type: t.Type(),
|
||||||
Payload: t.Payload(),
|
Payload: toPrintablePayload(t.Payload()),
|
||||||
Queue: t.Queue(),
|
Queue: t.Queue(),
|
||||||
MaxRetry: t.MaxRetry(),
|
MaxRetry: t.MaxRetry(),
|
||||||
Retried: t.Retried(),
|
Retried: t.Retried(),
|
||||||
@ -197,7 +219,7 @@ func toRetryTask(t *asynq.TaskInfo) *RetryTask {
|
|||||||
base := &BaseTask{
|
base := &BaseTask{
|
||||||
ID: t.ID(),
|
ID: t.ID(),
|
||||||
Type: t.Type(),
|
Type: t.Type(),
|
||||||
Payload: t.Payload(),
|
Payload: toPrintablePayload(t.Payload()),
|
||||||
Queue: t.Queue(),
|
Queue: t.Queue(),
|
||||||
MaxRetry: t.MaxRetry(),
|
MaxRetry: t.MaxRetry(),
|
||||||
Retried: t.Retried(),
|
Retried: t.Retried(),
|
||||||
@ -226,7 +248,7 @@ func toArchivedTask(t *asynq.TaskInfo) *ArchivedTask {
|
|||||||
base := &BaseTask{
|
base := &BaseTask{
|
||||||
ID: t.ID(),
|
ID: t.ID(),
|
||||||
Type: t.Type(),
|
Type: t.Type(),
|
||||||
Payload: t.Payload(),
|
Payload: toPrintablePayload(t.Payload()),
|
||||||
Queue: t.Queue(),
|
Queue: t.Queue(),
|
||||||
MaxRetry: t.MaxRetry(),
|
MaxRetry: t.MaxRetry(),
|
||||||
Retried: t.Retried(),
|
Retried: t.Retried(),
|
||||||
@ -250,7 +272,7 @@ type SchedulerEntry struct {
|
|||||||
ID string `json:"id"`
|
ID string `json:"id"`
|
||||||
Spec string `json:"spec"`
|
Spec string `json:"spec"`
|
||||||
TaskType string `json:"task_type"`
|
TaskType string `json:"task_type"`
|
||||||
TaskPayload []byte `json:"task_payload"`
|
TaskPayload string `json:"task_payload"`
|
||||||
Opts []string `json:"options"`
|
Opts []string `json:"options"`
|
||||||
NextEnqueueAt string `json:"next_enqueue_at"`
|
NextEnqueueAt string `json:"next_enqueue_at"`
|
||||||
// This field is omitted if there were no previous enqueue events.
|
// This field is omitted if there were no previous enqueue events.
|
||||||
@ -270,7 +292,7 @@ func toSchedulerEntry(e *asynq.SchedulerEntry) *SchedulerEntry {
|
|||||||
ID: e.ID,
|
ID: e.ID,
|
||||||
Spec: e.Spec,
|
Spec: e.Spec,
|
||||||
TaskType: e.Task.Type(),
|
TaskType: e.Task.Type(),
|
||||||
TaskPayload: e.Task.Payload(),
|
TaskPayload: toPrintablePayload(e.Task.Payload()),
|
||||||
Opts: opts,
|
Opts: opts,
|
||||||
NextEnqueueAt: e.Next.Format(time.RFC3339),
|
NextEnqueueAt: e.Next.Format(time.RFC3339),
|
||||||
PrevEnqueueAt: prev,
|
PrevEnqueueAt: prev,
|
||||||
@ -343,7 +365,7 @@ type WorkerInfo struct {
|
|||||||
TaskID string `json:"task_id"`
|
TaskID string `json:"task_id"`
|
||||||
Queue string `json:"queue"`
|
Queue string `json:"queue"`
|
||||||
TaskType string `json:"task_type"`
|
TaskType string `json:"task_type"`
|
||||||
TakPayload []byte `json:"task_payload"`
|
TakPayload string `json:"task_payload"`
|
||||||
Started string `json:"start_time"`
|
Started string `json:"start_time"`
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,7 +374,7 @@ func toWorkerInfo(info *asynq.WorkerInfo) *WorkerInfo {
|
|||||||
TaskID: info.TaskID,
|
TaskID: info.TaskID,
|
||||||
Queue: info.Queue,
|
Queue: info.Queue,
|
||||||
TaskType: info.TaskType,
|
TaskType: info.TaskType,
|
||||||
TakPayload: info.TaskPayload,
|
TakPayload: toPrintablePayload(info.TaskPayload),
|
||||||
Started: info.Started.Format(time.RFC3339),
|
Started: info.Started.Format(time.RFC3339),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -242,7 +242,7 @@ export interface DailyStat {
|
|||||||
// BaseTask corresponds to asynq.Task type.
|
// BaseTask corresponds to asynq.Task type.
|
||||||
interface BaseTask {
|
interface BaseTask {
|
||||||
type: string;
|
type: string;
|
||||||
payload: { [key: string]: any };
|
payload: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ActiveTask extends BaseTask {
|
export interface ActiveTask extends BaseTask {
|
||||||
@ -314,7 +314,7 @@ export interface SchedulerEntry {
|
|||||||
id: string;
|
id: string;
|
||||||
spec: string;
|
spec: string;
|
||||||
task_type: string;
|
task_type: string;
|
||||||
task_payload: { [key: string]: any };
|
task_payload: string;
|
||||||
options: string[];
|
options: string[];
|
||||||
next_enqueue_at: string;
|
next_enqueue_at: string;
|
||||||
// prev_enqueue_at will be omitted
|
// prev_enqueue_at will be omitted
|
||||||
|
@ -288,7 +288,7 @@ function Row(props: RowProps) {
|
|||||||
language="json"
|
language="json"
|
||||||
customStyle={{ margin: 0, maxWidth: 400 }}
|
customStyle={{ margin: 0, maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
{JSON.stringify(task.payload)}
|
{task.payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{task.canceling ? "Canceling" : "Running"}</TableCell>
|
<TableCell>{task.canceling ? "Canceling" : "Running"}</TableCell>
|
||||||
|
@ -331,7 +331,7 @@ function Row(props: RowProps) {
|
|||||||
language="json"
|
language="json"
|
||||||
customStyle={{ margin: 0, maxWidth: 400 }}
|
customStyle={{ margin: 0, maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
{JSON.stringify(task.payload)}
|
{task.payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{timeAgo(task.last_failed_at)}</TableCell>
|
<TableCell>{timeAgo(task.last_failed_at)}</TableCell>
|
||||||
|
@ -333,7 +333,7 @@ function Row(props: RowProps) {
|
|||||||
language="json"
|
language="json"
|
||||||
customStyle={{ margin: 0, maxWidth: 400 }}
|
customStyle={{ margin: 0, maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
{JSON.stringify(task.payload)}
|
{task.payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell align="right">{task.retried}</TableCell>
|
<TableCell align="right">{task.retried}</TableCell>
|
||||||
|
@ -365,7 +365,7 @@ function Row(props: RowProps) {
|
|||||||
language="json"
|
language="json"
|
||||||
customStyle={{ margin: 0, maxWidth: 400 }}
|
customStyle={{ margin: 0, maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
{JSON.stringify(task.payload)}
|
{task.payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{durationBefore(task.next_process_at)}</TableCell>
|
<TableCell>{durationBefore(task.next_process_at)}</TableCell>
|
||||||
|
@ -362,7 +362,7 @@ function Row(props: RowProps) {
|
|||||||
language="json"
|
language="json"
|
||||||
customStyle={{ margin: 0, maxWidth: 400 }}
|
customStyle={{ margin: 0, maxWidth: 400 }}
|
||||||
>
|
>
|
||||||
{JSON.stringify(task.payload)}
|
{task.payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{durationBefore(task.next_process_at)}</TableCell>
|
<TableCell>{durationBefore(task.next_process_at)}</TableCell>
|
||||||
|
@ -288,7 +288,7 @@ function Row(props: RowProps) {
|
|||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={clsx(isLastRow && classes.noBorder)}>
|
<TableCell className={clsx(isLastRow && classes.noBorder)}>
|
||||||
<SyntaxHighlighter language="json">
|
<SyntaxHighlighter language="json">
|
||||||
{JSON.stringify(entry.task_payload)}
|
{entry.task_payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className={clsx(isLastRow && classes.noBorder)}>
|
<TableCell className={clsx(isLastRow && classes.noBorder)}>
|
||||||
|
@ -282,7 +282,7 @@ function Row(props: RowProps) {
|
|||||||
language="json"
|
language="json"
|
||||||
customStyle={{ margin: 0 }}
|
customStyle={{ margin: 0 }}
|
||||||
>
|
>
|
||||||
{JSON.stringify(worker.task_payload)}
|
{worker.task_payload}
|
||||||
</SyntaxHighlighter>
|
</SyntaxHighlighter>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell>{worker.queue}</TableCell>
|
<TableCell>{worker.queue}</TableCell>
|
||||||
|
Loading…
Reference in New Issue
Block a user