Skip to content
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
4 changes: 3 additions & 1 deletion ProcessMaker/Console/Commands/Consumer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Exception;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Log;
use ProcessMaker\Facades\MessageBrokerService;

class Consumer extends Command
Expand Down Expand Up @@ -40,7 +41,8 @@ public function handle()
try {
MessageBrokerService::worker();
} catch (Exception $e) {
$this->warn($e->getMessage());
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
}
}
}
53 changes: 53 additions & 0 deletions ProcessMaker/Jobs/RunNayraServiceTask.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace ProcessMaker\Jobs;

use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use ProcessMaker\Facades\WorkflowManager;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;

class RunNayraServiceTask implements ShouldQueue
{
use Dispatchable,
InteractsWithQueue,
Queueable,
SerializesModels;

public $tokenId;

public $userId;

/**
* Create a new job instance.
*
* @param \ProcessMaker\Models\ProcessRequestToken $token
* @param array $data
*/
public function __construct(TokenInterface $token)
{
$this->tokenId = $token->getKey();
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
{
// Get token
$token = ProcessRequestToken::find($this->tokenId);
$token->loadTokenProperties();
$instance = $token->processRequest;
$instance->loadProcessRequestInstance();
$token->setInstance($instance);

// Run service task
WorkflowManager::handleServiceTask($token);
}
}
14 changes: 14 additions & 0 deletions ProcessMaker/Models/ProcessRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -907,4 +907,18 @@ public function getMedia(string $collectionName = 'default', $filters = []): Col
{
return \ProcessMaker\Models\Media::getFilesRequest($this);
}

public function getErrors()
{
if ($this->errors) {
return $this->errors;
}
// select tokens with errors
return $this->tokens()
->select('token_properties->error as message', 'created_at', 'element_name')
->where('status', '=', ActivityInterface::TOKEN_STATE_FAILING)
->limit(10)
->get()
->toArray();
}
}
2 changes: 1 addition & 1 deletion ProcessMaker/Models/ProcessRequestToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ public function logError(Throwable $error, FlowElementInterface $bpmnElement)

public function updateTokenProperties()
{
$allowed = ['conditionals', 'loopCharacteristics', 'data'];
$allowed = ['conditionals', 'loopCharacteristics', 'data', 'error'];
$this->token_properties = array_filter(
$this->getProperties(),
function ($key) use ($allowed) {
Expand Down
31 changes: 28 additions & 3 deletions ProcessMaker/Nayra/Managers/WorkflowManagerRabbitMq.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
use ProcessMaker\Facades\MessageBrokerService;
use ProcessMaker\Facades\WorkflowManager;
use ProcessMaker\GenerateAccessToken;
use ProcessMaker\Jobs\RunNayraServiceTask;
use ProcessMaker\Managers\DataManager;
use ProcessMaker\Managers\SignalManager;
use ProcessMaker\Models\EnvironmentVariable;
use ProcessMaker\Models\Process as Definitions;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this reference is not used in this file...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Definitions is used as alias of Process. I removed the use ProcessMaker\Models\Process; and use Definitions to keep the logic of the class

use ProcessMaker\Models\Process;
use ProcessMaker\Models\ProcessCollaboration;
use ProcessMaker\Models\ProcessRequest;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\Script;
use ProcessMaker\Models\User;
use ProcessMaker\Nayra\Contracts\Bpmn\BoundaryEventInterface;
Expand All @@ -30,11 +31,17 @@
class WorkflowManagerRabbitMq extends WorkflowManagerDefault implements WorkflowManagerInterface
{
const ACTION_START_PROCESS = 'START_PROCESS';

const ACTION_COMPLETE_TASK = 'COMPLETE_TASK';

const ACTION_TRIGGER_INTERMEDIATE_EVENT = 'TRIGGER_INTERMEDIATE_EVENT';

const ACTION_RUN_SCRIPT = 'RUN_SCRIPT';

const ACTION_TRIGGER_BOUNDARY_EVENT = 'TRIGGER_BOUNDARY_EVENT';

const ACTION_TRIGGER_MESSAGE_EVENT = 'TRIGGER_MESSAGE_EVENT';

const ACTION_TRIGGER_SIGNAL_EVENT = 'TRIGGER_SIGNAL_EVENT';

/**
Expand Down Expand Up @@ -222,6 +229,16 @@ public function runServiceTask(ServiceTaskInterface $serviceTask, TokenInterface
// Log execution
Log::info('Dispatch a service task: ' . $serviceTask->getId());

RunNayraServiceTask::dispatch($token)->onQueue('bpmn');
}

/**
* Run a service task.
*
* @param ProcessRequestToken $token
*/
public function handleServiceTask(ProcessRequestToken $token)
{
// Get complementary information
$element = $token->getDefinition(true);
$instance = $token->processRequest;
Expand Down Expand Up @@ -395,7 +412,7 @@ public function throwSignalEventProcess($processId, $signalRef, array $data)
// Get complementary information
$userId = $this->getCurrentUserId();
// get process variable
$process = Process::find($processId);
$process = Definitions::find($processId);
$definitions = $process->getDefinitions();
$catches = SignalManager::getSignalCatchEvents($signalRef, $definitions);
$processVariable = '';
Expand Down Expand Up @@ -480,17 +497,25 @@ private function serializeState(ProcessRequest $instance)
$tokensRows = [];
$tokens = $request->tokens()->where('status', '!=', 'CLOSED')->where('status', '!=', 'TRIGGERED')->get();
foreach ($tokens as $token) {
$tokensRows[] = array_merge($token->token_properties ?: [], [
$tokenRow = array_merge($token->token_properties ?: [], [
'id' => $token->uuid,
'status' => $token->status,
'index' => $token->element_index,
'element_id' => $token->element_id,
'created_at' => $token->created_at->getTimestamp(),
]);
if ($token->subprocess_request_id) {
$subRequest = ProcessRequest::select(['process_version_id', 'uuid'])
->find($token->subprocess_request_id);
$tokenRow['subprocess_request_id'] = $subRequest->uuid;
$tokenRow['subprocess_request_version'] = $subRequest->process_version_id;
}
$tokensRows[] = $tokenRow;
}

return [
'id' => $request->uuid,
'process_version_id' => $request->process_version_id,
'callable_id' => $request->callable_id,
'collaboration_uuid' => $request->collaboration_uuid,
'data' => $request->data,
Expand Down
3 changes: 2 additions & 1 deletion ProcessMaker/Nayra/Repositories/Deserializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use ProcessMaker\Nayra\Contracts\Bpmn\EventDefinitionInterface;
use ProcessMaker\Nayra\Contracts\Bpmn\TokenInterface;
use ProcessMaker\Nayra\Contracts\Engine\ExecutionInstanceInterface;
use ProcessMaker\Nayra\Contracts\Storage\BpmnDocumentInterface;
use ProcessMaker\Repositories\BpmnDocument;
use ProcessMaker\Repositories\DefinitionsRepository;
use ProcessMaker\Repositories\ExecutionInstanceRepository;
Expand Down Expand Up @@ -56,7 +57,7 @@ private function findProcessDefinition($modelId): BpmnDocument
$version = ProcessVersion::find($modelId);
$model = $version->process;

$definition = new BpmnDocument($model);
$definition = app(BpmnDocumentInterface::class, ['process' => $model]);
$definition->setFactory($this->factory);
$definition->loadXML($version->bpmn);

Expand Down
7 changes: 6 additions & 1 deletion ProcessMaker/Nayra/Repositories/PersistenceHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ public function save(array $transaction)
case 'instance_updated':
$this->persistInstanceUpdated($transaction);
break;
case 'call_activity_activated':
$this->persistCallActivityActivated($transaction);
break;
case 'schedule_date':
$this->persistScheduleDate($transaction);
break;
Expand All @@ -138,8 +141,10 @@ public function save(array $transaction)
throw new Exception('Unknown transaction type ' . $transaction['type']);
}
} catch (Exception $error) {
error_log($error->getMessage());
Log::error($error->getMessage());
if ($transaction['token']) {
Log::error($error->getTraceAsString());
if (!empty($transaction['token'])) {
$token = $this->deserializer->unserializeToken($transaction['token']);
$request = $token->getInstance();
if ($request && $request instanceof ProcessRequest) {
Expand Down
17 changes: 17 additions & 0 deletions ProcessMaker/Nayra/Repositories/PersistenceTokenTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

namespace ProcessMaker\Nayra\Repositories;

use ProcessMaker\Repositories\TokenRepository;

trait PersistenceTokenTrait
{
protected TokenRepository $tokenRepository;

/**
* Persists instance and token data when a token arrives to an activity
*
Expand Down Expand Up @@ -208,4 +212,17 @@ public function persistEventBasedGatewayActivated(array $transaction)
$consumedTokens = $this->deserializer->unserializeTokensCollection($transaction['consumed_tokens']);
$this->tokenRepository->persistEventBasedGatewayActivated($gateway, $passedToken, $consumedTokens);
}

/**
* Persists a Call Activity Activated
*
* @param array $transaction
*/
public function persistCallActivityActivated(array $transaction)
{
$token = $this->deserializer->unserializeToken($transaction['token']);
$subprocessInstance = $this->deserializer->unserializeInstance($transaction['subprocess']);
$startId = $transaction['start_id'];
$this->tokenRepository->persistCallActivityActivated($token, $subprocessInstance, $startId);
}
}
3 changes: 2 additions & 1 deletion ProcessMaker/Repositories/TokenRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use ProcessMaker\Models\ProcessCollaboration;
use ProcessMaker\Models\ProcessRequest as Instance;
use ProcessMaker\Models\ProcessRequestToken as Token;
use ProcessMaker\Models\ProcessRequestToken;
use ProcessMaker\Models\User;
use ProcessMaker\Nayra\Bpmn\Collection;
use ProcessMaker\Nayra\Bpmn\Models\EndEvent;
Expand Down Expand Up @@ -201,7 +202,7 @@ private function assignTaskUser(ActivityInterface $activity, TokenInterface $tok
* Persists instance and token data when a token within an activity change to error state
*
* @param ActivityInterface $activity
* @param TokenInterface $token
* @param TokenInterface|ProcessRequestToken $token
*
* @return mixed
*/
Expand Down
2 changes: 1 addition & 1 deletion resources/js/requests/components/RequestErrors.vue
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<style lang="scss" scoped>
.error-body {
word-break: break-word;
overflow-x: scroll;
overflow-x: auto;
font-size: 87.5%;
max-width: 992px; // Not a fan of hard-coding this value, but it's equivalent to $screen-md-max
}
Expand Down
2 changes: 1 addition & 1 deletion resources/views/requests/show.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ class="d-inline-flex pull-left align-items-center" :input-data="requestBy" displ
canViewPrint: @json($canPrintScreens),
status: 'ACTIVE',
userRequested: [],
errorLogs: @json(['data' => $request->errors]),
errorLogs: @json(['data' => $request->getErrors()]),
disabled: false,
retryDisabled: false,
packages: [],
Expand Down