Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW: Show job data in descriptor edit form. #312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,17 @@ As a consequence, the work might end up being very fragmented and each chunk may

Some projects do not mind this however, so this solution may still be quite suitable.

## Show job data

In case you need an easy access to additonal job data via CMS for debug purposes enable the `show_job_data` option by including the configuration below.

```yaml
Symbiote\QueuedJobs\DataObjects\QueuedJobDescriptor:
show_job_data: true
```

This will add Job data and Messages raw tabs to the job descriptor edit form. Displayed information is read only.

## Contributing

### Translations
Expand Down
38 changes: 38 additions & 0 deletions src/DataObjects/QueuedJobDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use SilverStripe\Forms\HeaderField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Forms\TextField;
use SilverStripe\ORM\DataObject;
use SilverStripe\ORM\FieldType\DBDatetime;
Expand Down Expand Up @@ -132,6 +133,14 @@ class QueuedJobDescriptor extends DataObject
*/
private static $default_sort = 'Created DESC';

/**
* Show job data and raw messages in the edit form
*
* @config
* @var bool
*/
private static $show_job_data = false;

public function requireDefaultRecords()
{
parent::requireDefaultRecords();
Expand Down Expand Up @@ -318,6 +327,21 @@ public function getJobTypeString()
return isset($map[$this->JobType]) ? $map[$this->JobType] : '(Unknown)';
}

/**
* @return string|null
*/
public function getSavedJobDataPreview()
{
return $this->SavedJobData;
}

/**
* @return string|null
*/
public function getMessagesRaw()
{
return $this->SavedJobMessages;
}

/**
* Return a map of numeric JobType values to localisable string representations.
Expand Down Expand Up @@ -507,6 +531,20 @@ public function getCMSFields()
$fields->addFieldToTab('Root.Messages', LiteralField::create('Messages', $this->getMessages()));
}

if ($this->config()->get('show_job_data')) {
$fields->addFieldsToTab('Root.JobData', [
$jobDataPreview = TextareaField::create('SavedJobDataPreview', 'Job Data'),
]);

$jobDataPreview->setReadonly(true);

$fields->addFieldsToTab('Root.MessagesRaw', [
$messagesRaw = TextareaField::create('MessagesRaw', 'Messages Raw'),
]);

$messagesRaw->setReadonly(true);
}

if (Permission::check('ADMIN')) {
return $fields;
}
Expand Down