Skip to content

Commit

Permalink
Merge branch 'master' of github.com:freescout-helpdesk/freescout into…
Browse files Browse the repository at this point in the history
… dist
  • Loading branch information
freescout-help-desk committed Dec 29, 2018
2 parents b91e192 + 2cb7d81 commit cc78c0e
Show file tree
Hide file tree
Showing 9 changed files with 54 additions and 25 deletions.
1 change: 0 additions & 1 deletion app/Attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ public static function deleteByIds($attachment_ids)

// Delete from disk
foreach ($attachments as $attachment) {
echo $attachment->getStorageFilePath().' ';
Storage::delete($attachment->getStorageFilePath());
}

Expand Down
62 changes: 46 additions & 16 deletions app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class Kernel extends ConsoleKernel
*/
protected function schedule(Schedule $schedule)
{
// Keep in mind that this function is also called on clearing cache.

// Remove failed jobs
$schedule->command('queue:flush')
->weekly();
Expand Down Expand Up @@ -81,26 +83,31 @@ protected function schedule(Schedule $schedule)
// Command runs as subprocess and sets cache mutex. If schedule:run command is killed
// subprocess does not clear the mutex and it stays in the cache until cache:clear is executed.
// By default, the lock will expire after 24 hours.
//
// cache:clear clears the mutex, but sometimes process continues running, so we need to kill it.

if (function_exists('shell_exec')) {
$running_commands = 0;

try {
$processes = preg_split("/[\r\n]/", shell_exec("ps aux | grep 'queue:work'"));
foreach ($processes as $process) {
preg_match("/^[\S]+\s+([\d]+)\s+/", $process, $m);
if (!preg_match("/(sh \-c|grep )/", $process) && !empty($m[1])) {
$running_commands++;
}
}
} catch (\Exception $e) {
// Do nothing
}
if ($running_commands > 1) {
$running_commands = $this->getRunningQueueProcesses();

if (count($running_commands) > 1) {
// Stop all queue:work processes.
// queue:work command is stopped by settings a cache key
\Cache::forever('illuminate:queue:restart', Carbon::now()->getTimestamp());
// Sometimes processes stuck and just continue running, so we need to kill them.
// Sleep to let processes stop.
sleep(1);
// Check processes again.
$worker_pids = $this->getRunningQueueProcesses();

if (count($worker_pids) > 1) {
// Current process also has to be killed, as otherwise it "stucks"
// $current_pid = getmypid();
// foreach ($worker_pids as $i => $pid) {
// if ($pid == $current_pid) {
// unset($worker_pids[$i]);
// break;
// }
// }
shell_exec('kill '.implode(' | kill ', $worker_pids));
}
}
}

Expand All @@ -110,6 +117,29 @@ protected function schedule(Schedule $schedule)
->sendOutputTo(storage_path().'/logs/queue-jobs.log');
}

/**
* Get pids of the queue:work processes.
*
* @return [type] [description]
*/
protected function getRunningQueueProcesses()
{
$pids = [];

try {
$processes = preg_split("/[\r\n]/", shell_exec("ps aux | grep 'queue:work'"));
foreach ($processes as $process) {
preg_match("/^[\S]+\s+([\d]+)\s+/", $process, $m);
if (!preg_match("/(sh \-c|grep )/", $process) && !empty($m[1])) {
$pids[] = $m[1];
}
}
} catch (\Exception $e) {
// Do nothing
}
return $pids;
}

/**
* Register the commands for the application.
*
Expand Down
2 changes: 1 addition & 1 deletion config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
| or any other location as required by the application or its packages.
*/

'version' => '1.1.4',
'version' => '1.1.5',

/*
|--------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion public/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -2286,7 +2286,7 @@ ul.prev-convs {
}
.thread-body {
margin-left: 0;
padding-left: 3px;
padding-left: 12px;
}
.thread-to-first,
.thread-type {
Expand Down
2 changes: 1 addition & 1 deletion public/installer/css/style.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2612,6 +2612,7 @@ function converstationBulkActionsInit()

function switchToNote()
{
$(".conv-reply-block").addClass('hidden');
$('.conv-add-note:first').click();
}

Expand Down
4 changes: 2 additions & 2 deletions resources/views/conversations/editor_bottom_toolbar.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@endif
</div>
<span class="editor-btm-text">{{ __('Status') }}:</span>
{{-- Note always changes status to Active. Note never changes Assignee --}}
<select name="status" class="form-control" data-parsley-exclude="true" data-reply-status="{{ $mailbox->ticket_status }}" data-note-status="{{ App\Mailbox::TICKET_STATUS_ACTIVE }}">
{{-- Note keeps status. Note never changes Assignee --}}
<select name="status" class="form-control" data-parsley-exclude="true" data-reply-status="{{ $mailbox->ticket_status }}" data-note-status="{{ $mailbox->ticket_status }}">
<option value="{{ App\Mailbox::TICKET_STATUS_ACTIVE }}" @if ($mailbox->ticket_status == App\Mailbox::TICKET_STATUS_ACTIVE)selected="selected"@endif>{{ __('Active') }}</option>
<option value="{{ App\Mailbox::TICKET_STATUS_PENDING }}" @if ($mailbox->ticket_status == App\Mailbox::TICKET_STATUS_PENDING)selected="selected"@endif>{{ __('Pending') }}</option>
<option value="{{ App\Mailbox::TICKET_STATUS_CLOSED }}" @if ($mailbox->ticket_status == App\Mailbox::TICKET_STATUS_CLOSED)selected="selected"@endif>{{ __('Closed') }}</option>
Expand Down
4 changes: 2 additions & 2 deletions resources/views/conversations/view.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,8 +259,8 @@
@if ( $thread->opened_at )
<div class='thread-opened-at'><i class="glyphicon glyphicon-eye-open"></i> {{ __("Customer viewed") }} {{ App\User::dateDiffForHumansWithHours($thread->opened_at) }}</div>
@endif
@include('conversations/partials/thread_attachments')
</div>
@include('conversations/partials/thread_attachments')
</div>
</div>
@else
Expand Down Expand Up @@ -335,7 +335,7 @@
$is_first = false;
}
@endphp
@if (!empty($is_first) && $conversation->threads_count > 2)<a href="#thread-{{ $threads[count($threads)-1]->id }}" class="thread-to-first" data-toggle="tooltip" title="{{ __('Scroll to the Beginning') }}"><i class="glyphicon glyphicon-arrow-down"></i> </a>@endif
@if (!empty($is_first) && $conversation->threads_count > 2)<a href="#thread-{{ $threads[count($threads)-1]->id }}" class="thread-to-first" data-toggle="tooltip" title="{{ __('To the First Message') }}"><i class="glyphicon glyphicon-arrow-down"></i> </a>@endif
{{--<span class="thread-type">#{{ $thread_num }} <span>·</span> </span>--}}
@endif
@endif
Expand Down
1 change: 0 additions & 1 deletion resources/views/mailboxes/connection.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@
</div>
</div>
</div>
<hr class="clearfix"/>
</div>

<div class="form-group">
Expand Down

0 comments on commit cc78c0e

Please sign in to comment.