Skip to content

Commit

Permalink
Merge branch 'master' into hubbub
Browse files Browse the repository at this point in the history
  • Loading branch information
emmachughes committed Dec 8, 2023
2 parents f77793e + efbfd69 commit 4a0f412
Show file tree
Hide file tree
Showing 39 changed files with 4,157 additions and 1,202 deletions.
32 changes: 0 additions & 32 deletions chart/templates/apis/contentauthor.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -155,38 +155,6 @@ spec:
memory: 200Mi
serviceAccount: contentauthor
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: contentauthor-rabbitmq-subscriber
spec:
replicas: 1
selector:
matchLabels:
app: contentauthor-rabbitmq-subscriber
template:
metadata:
labels:
app: contentauthor-rabbitmq-subscriber
fluentd-parser: laravel-json
spec:
containers:
- name: main
image: "public.ecr.aws/f0t8l9h1/api-contentauthor-phpfpm:{{ .Chart.AppVersion }}"
command:
- php
- artisan
- laravel-rabbitmq-pubsub:consumer
{{- include "apis.contentauthor.env" . | indent 10 }}
resources:
limits:
cpu: 500m
memory: 1500Mi
requests:
cpu: 20m
memory: 200Mi
serviceAccount: contentauthor
---
apiVersion: batch/v1
kind: CronJob
metadata:
Expand Down
18 changes: 0 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -204,24 +204,6 @@ services:
- ./sourcecode/apis/contentauthor:/app
- ./data/nginx/ca:/usr/local/share/ca-certificates:ro

contentauthor-subscribers:
build:
context: ./sourcecode/apis/contentauthor
target: dev
depends_on:
contentauthor-fpm:
condition: service_healthy
rabbitmq:
condition: service_healthy
env_file:
- ./localSetup/projects/content-author/.env
- ./localSetup/.env
command: [php, artisan, 'laravel-rabbitmq-pubsub:consumer']
volumes:
- ./localSetup/projects/content-author/startup.sh:/startup.sh
- ./sourcecode/apis/contentauthor:/app
- ./data/nginx/ca:/usr/local/share/ca-certificates:ro

contentauthor-cron:
build:
context: ./sourcecode/apis/contentauthor
Expand Down
4 changes: 0 additions & 4 deletions localSetup/projects/content-author/.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ VERSION_OAUTH_SECRET=91bbc285-a57a-405c-97cb-c9549ced42f0
ENABLE_LICENSING=true

FEATURE_CONTEXT_COLLABORATION=true
RABBITMQ_HOST=rabbitmq
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest

ENABLE_NDLA_IMPORT=true
IMPORT_USERID=ndlauser
Expand Down
68 changes: 0 additions & 68 deletions sourcecode/apis/contentauthor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@ $ CACHE_DRIVER=file php artisan cerpus:init-versioning

# Starting the internal queue worker

#### `This refers to the internal queues, not the RabbitMQ queue workers`

[Laravel Horizon](https://laravel.com/docs/6.x/horizon) will handle all the internal queues.

See `config/horizon.php` for config options if you want to modify/tweak the set up.
Expand All @@ -97,72 +95,6 @@ For development purposes you can use the `sync` queue driver.
In .env
`FEATURE_CONTEXT_COLLABORATION=true`

## Creating a new message handler

To create a new message processing worker follow these steps. In the example we will consume a queue named `my_messages`

1. `php artisan bowler:make:queue my_messages MyMessages`
2. The my_messages queue has been added to `app/Messaging/queue.php`. Edit this file to finish setting up the queue. Refer to the Bowler docs / source code for config options.
3. To implement the handler edit `app/Messaging/Handlers/MyMessageHandler.php@handle`

```
public function handle($msg)
{
echo "Look, I'm processing the {$msg->body}\n";
}
```

I recommend farming out the actual processing of the message to an entity outside the message handler to ease the testability and portability of the processing should we decide to replace RabbitMQ in the future. See `app/Messaging/Handlers/EdStepCollaborationhandler@handle`

## Starting the worker from the command line

1. `php artisan bowler:consume my_messages`

If you publish a message to the exchange configured in `queue.php` you should see the message being received and processed by Content Author.

## Handling the worker in production

Use Supervisor or something similar to start the workers. You will need one supervisor config per queue, but may start multiple workers to handle the queue on capacity problems (see `numprocs_start`). In a setup where content author is scaled horizontally only one server needs to run the worker. The workers may run on a dedicated machine.

### Configuring the RabbitMQ connection

These .env variables (with defaults) are available for configuration.

```
RABBITMQ_HOST=localhost
RABBITMQ_PORT=5672
RABBITMQ_USERNAME=guest
RABBITMQ_PASSWORD=guest
```

### Starting the edstepmessages worker

Assumes that Content Author is installed in /var/www/content-author.
This will start two new workers handling events on the edstep_messages queue on system boot.
Save this as /etc/supervisor/config/edstepmessages.conf

```
[program:edstepmessages]
process_name=%(program_name)s_%(process_num)02d
command=/usr/bin/php /var/www/content-author/artisan bowler:consume ca-EdStep-CollaborationUpdates
directory=/var/www/content-author/
user=www-data
group=www-data
numprocs=2
autostart=true
```

```
$ sudo supervisorctl reread
$ sudo supervisorctl start edstepmessages
```

See [https://laravel.com/docs/6.x/queues#supervisor-configuration](https://laravel.com/docs/6.x/queues#supervisor-configuration) for another example directly related to Laravel queues

### Restart queue worker on update

As the queue handlers are long lived processes you must restart them when the code has been updated. Add `supervisorctl restart edstepmessages` after migrations are run.

# LTI params

Content Author will use some LTI parameters if passed in.
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

10 changes: 0 additions & 10 deletions sourcecode/apis/contentauthor/app/Gdpr/Handlers/Processor.php

This file was deleted.

42 changes: 0 additions & 42 deletions sourcecode/apis/contentauthor/app/Gdpr/Handlers/ShareProcessor.php

This file was deleted.

19 changes: 1 addition & 18 deletions sourcecode/apis/contentauthor/app/H5PContent.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use App\Libraries\H5P\Packages\QuestionSet;
use App\Libraries\Versioning\VersionableObject;
use H5PCore;
use H5PFrameworkInterface;
use H5PMetadata;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;
Expand Down Expand Up @@ -336,23 +335,7 @@ public static function getContentTypeInfo(string $contentType): ?ContentTypeData
return null;
}

$icon = null;

if ($library->has_icon) {
$h5pFramework = app(H5PFrameworkInterface::class);
$library_folder = $library->getFolderName();
$icon_path = $h5pFramework->getLibraryFileUrl($library_folder, 'icon.svg');

if (!empty($icon_path)) {
$icon = $icon_path;
}
}

if ($icon === null) {
$icon = url('/graphical/h5p_logo.svg');
}

return new ContentTypeDataObject("H5P", $contentType, $library->title, $icon);
return new ContentTypeDataObject("H5P", $contentType, $library->title, $library->getIconUrl());
}

public function getUrl(): string
Expand Down
18 changes: 18 additions & 0 deletions sourcecode/apis/contentauthor/app/H5PLibrary.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App;

use H5PFrameworkInterface;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
Expand Down Expand Up @@ -350,4 +351,21 @@ public function includeImageWidth(): bool
{
return !in_array($this->name, ['H5P.ThreeImage', 'H5P.NDLAThreeImage']);
}

public function getIconUrl(): string
{
$icon = null;

if ($this->has_icon) {
$h5pFramework = app(H5PFrameworkInterface::class);
$library_folder = $this->getFolderName();
$icon_path = $h5pFramework->getLibraryFileUrl($library_folder, 'icon.svg');

if (!empty($icon_path)) {
$icon = $icon_path;
}
}

return $icon ?? url('/graphical/h5p_logo.svg');
}
}
Loading

0 comments on commit 4a0f412

Please sign in to comment.