diff --git a/conversion_helpers.go b/conversion_helpers.go
index bc4b694..9d073e4 100644
--- a/conversion_helpers.go
+++ b/conversion_helpers.go
@@ -2,6 +2,8 @@ package main
import (
"time"
+ "unicode"
+ "unicode/utf8"
"github.com/hibiken/asynq"
)
@@ -86,7 +88,7 @@ func toDailyStatsList(in []*asynq.DailyStats) []*DailyStats {
type BaseTask struct {
ID string `json:"id"`
Type string `json:"type"`
- Payload []byte `json:"payload"`
+ Payload string `json:"payload"`
Queue string `json:"queue"`
MaxRetry int `json:"max_retry"`
Retried int `json:"retried"`
@@ -114,7 +116,7 @@ func toActiveTask(t *asynq.TaskInfo) *ActiveTask {
base := &BaseTask{
ID: t.ID(),
Type: t.Type(),
- Payload: t.Payload(),
+ Payload: toPrintablePayload(t.Payload()),
Queue: t.Queue(),
MaxRetry: t.MaxRetry(),
Retried: t.Retried(),
@@ -140,7 +142,7 @@ func toPendingTask(t *asynq.TaskInfo) *PendingTask {
base := &BaseTask{
ID: t.ID(),
Type: t.Type(),
- Payload: t.Payload(),
+ Payload: toPrintablePayload(t.Payload()),
Queue: t.Queue(),
MaxRetry: t.MaxRetry(),
Retried: t.Retried(),
@@ -164,11 +166,31 @@ type ScheduledTask struct {
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 {
base := &BaseTask{
ID: t.ID(),
Type: t.Type(),
- Payload: t.Payload(),
+ Payload: toPrintablePayload(t.Payload()),
Queue: t.Queue(),
MaxRetry: t.MaxRetry(),
Retried: t.Retried(),
@@ -197,7 +219,7 @@ func toRetryTask(t *asynq.TaskInfo) *RetryTask {
base := &BaseTask{
ID: t.ID(),
Type: t.Type(),
- Payload: t.Payload(),
+ Payload: toPrintablePayload(t.Payload()),
Queue: t.Queue(),
MaxRetry: t.MaxRetry(),
Retried: t.Retried(),
@@ -226,7 +248,7 @@ func toArchivedTask(t *asynq.TaskInfo) *ArchivedTask {
base := &BaseTask{
ID: t.ID(),
Type: t.Type(),
- Payload: t.Payload(),
+ Payload: toPrintablePayload(t.Payload()),
Queue: t.Queue(),
MaxRetry: t.MaxRetry(),
Retried: t.Retried(),
@@ -250,7 +272,7 @@ type SchedulerEntry struct {
ID string `json:"id"`
Spec string `json:"spec"`
TaskType string `json:"task_type"`
- TaskPayload []byte `json:"task_payload"`
+ TaskPayload string `json:"task_payload"`
Opts []string `json:"options"`
NextEnqueueAt string `json:"next_enqueue_at"`
// This field is omitted if there were no previous enqueue events.
@@ -270,7 +292,7 @@ func toSchedulerEntry(e *asynq.SchedulerEntry) *SchedulerEntry {
ID: e.ID,
Spec: e.Spec,
TaskType: e.Task.Type(),
- TaskPayload: e.Task.Payload(),
+ TaskPayload: toPrintablePayload(e.Task.Payload()),
Opts: opts,
NextEnqueueAt: e.Next.Format(time.RFC3339),
PrevEnqueueAt: prev,
@@ -343,7 +365,7 @@ type WorkerInfo struct {
TaskID string `json:"task_id"`
Queue string `json:"queue"`
TaskType string `json:"task_type"`
- TakPayload []byte `json:"task_payload"`
+ TakPayload string `json:"task_payload"`
Started string `json:"start_time"`
}
@@ -352,7 +374,7 @@ func toWorkerInfo(info *asynq.WorkerInfo) *WorkerInfo {
TaskID: info.TaskID,
Queue: info.Queue,
TaskType: info.TaskType,
- TakPayload: info.TaskPayload,
+ TakPayload: toPrintablePayload(info.TaskPayload),
Started: info.Started.Format(time.RFC3339),
}
}
diff --git a/ui/src/api.ts b/ui/src/api.ts
index 3418c38..574dbcb 100644
--- a/ui/src/api.ts
+++ b/ui/src/api.ts
@@ -242,7 +242,7 @@ export interface DailyStat {
// BaseTask corresponds to asynq.Task type.
interface BaseTask {
type: string;
- payload: { [key: string]: any };
+ payload: string;
}
export interface ActiveTask extends BaseTask {
@@ -314,7 +314,7 @@ export interface SchedulerEntry {
id: string;
spec: string;
task_type: string;
- task_payload: { [key: string]: any };
+ task_payload: string;
options: string[];
next_enqueue_at: string;
// prev_enqueue_at will be omitted
diff --git a/ui/src/components/ActiveTasksTable.tsx b/ui/src/components/ActiveTasksTable.tsx
index d73d649..3f4cc38 100644
--- a/ui/src/components/ActiveTasksTable.tsx
+++ b/ui/src/components/ActiveTasksTable.tsx
@@ -288,7 +288,7 @@ function Row(props: RowProps) {
language="json"
customStyle={{ margin: 0, maxWidth: 400 }}
>
- {JSON.stringify(task.payload)}
+ {task.payload}
{task.canceling ? "Canceling" : "Running"}
diff --git a/ui/src/components/ArchivedTasksTable.tsx b/ui/src/components/ArchivedTasksTable.tsx
index be2ffc6..b9ca6c4 100644
--- a/ui/src/components/ArchivedTasksTable.tsx
+++ b/ui/src/components/ArchivedTasksTable.tsx
@@ -331,7 +331,7 @@ function Row(props: RowProps) {
language="json"
customStyle={{ margin: 0, maxWidth: 400 }}
>
- {JSON.stringify(task.payload)}
+ {task.payload}
{timeAgo(task.last_failed_at)}
diff --git a/ui/src/components/PendingTasksTable.tsx b/ui/src/components/PendingTasksTable.tsx
index 5564a54..f5e7d75 100644
--- a/ui/src/components/PendingTasksTable.tsx
+++ b/ui/src/components/PendingTasksTable.tsx
@@ -333,7 +333,7 @@ function Row(props: RowProps) {
language="json"
customStyle={{ margin: 0, maxWidth: 400 }}
>
- {JSON.stringify(task.payload)}
+ {task.payload}
{task.retried}
diff --git a/ui/src/components/RetryTasksTable.tsx b/ui/src/components/RetryTasksTable.tsx
index 9fefd60..cda44d2 100644
--- a/ui/src/components/RetryTasksTable.tsx
+++ b/ui/src/components/RetryTasksTable.tsx
@@ -365,7 +365,7 @@ function Row(props: RowProps) {
language="json"
customStyle={{ margin: 0, maxWidth: 400 }}
>
- {JSON.stringify(task.payload)}
+ {task.payload}
{durationBefore(task.next_process_at)}
diff --git a/ui/src/components/ScheduledTasksTable.tsx b/ui/src/components/ScheduledTasksTable.tsx
index 2ef9f9e..7dffca1 100644
--- a/ui/src/components/ScheduledTasksTable.tsx
+++ b/ui/src/components/ScheduledTasksTable.tsx
@@ -362,7 +362,7 @@ function Row(props: RowProps) {
language="json"
customStyle={{ margin: 0, maxWidth: 400 }}
>
- {JSON.stringify(task.payload)}
+ {task.payload}
{durationBefore(task.next_process_at)}
diff --git a/ui/src/components/SchedulerEntriesTable.tsx b/ui/src/components/SchedulerEntriesTable.tsx
index 2926d12..61e9753 100644
--- a/ui/src/components/SchedulerEntriesTable.tsx
+++ b/ui/src/components/SchedulerEntriesTable.tsx
@@ -288,7 +288,7 @@ function Row(props: RowProps) {
- {JSON.stringify(entry.task_payload)}
+ {entry.task_payload}
diff --git a/ui/src/components/ServersTable.tsx b/ui/src/components/ServersTable.tsx
index d593b7e..710a1d7 100644
--- a/ui/src/components/ServersTable.tsx
+++ b/ui/src/components/ServersTable.tsx
@@ -282,7 +282,7 @@ function Row(props: RowProps) {
language="json"
customStyle={{ margin: 0 }}
>
- {JSON.stringify(worker.task_payload)}
+ {worker.task_payload}
{worker.queue}