Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
760298c
intial_websockets_setup
ozer550 Jun 28, 2022
798822e
try_fixin_INSTALLED_APPS_error
ozer550 Jun 28, 2022
9d2f27c
updated requirements.in file
ozer550 Jun 28, 2022
a3bc91b
FIX_Django_Settings_Error
ozer550 Jun 28, 2022
44ef339
FIX_test_cases
ozer550 Jun 30, 2022
f8d02ed
send_data_from_frontend
ozer550 Jul 1, 2022
b0835e3
inject proper channel_id while making websocket request
ozer550 Jul 1, 2022
07041bc
implement handel_changes from sync api in websockets
ozer550 Jul 2, 2022
b656473
FIX_unit_tests
ozer550 Jul 5, 2022
1b9b63c
update redis version
ozer550 Jul 7, 2022
b7a39f1
Add more unit tests
ozer550 Jul 8, 2022
1508d41
refine pr
ozer550 Jul 16, 2022
11ce747
refine PR
ozer550 Jul 19, 2022
64dd28f
Merge pull request #3433 from ozer550/websockets_initial_setup
bjester Jul 20, 2022
93c8505
Fix merge conflicts in requirements files
bjester Jul 20, 2022
721a052
setup django signals for change object
ozer550 Jul 15, 2022
ad1461a
properly handle cases in signals
ozer550 Jul 18, 2022
279daf4
complete tests for signals
ozer550 Aug 2, 2022
40a08fe
fix rebase
ozer550 Aug 2, 2022
aa54a24
broken test_cannot_create_files
ozer550 Aug 2, 2022
4092a3f
fix typecasting
ozer550 Aug 2, 2022
cc9982a
add helper functions for tests
ozer550 Aug 5, 2022
e9bc522
refactored tests
ozer550 Aug 7, 2022
afe273a
fix typos
ozer550 Aug 7, 2022
cc1db42
final refactor
ozer550 Aug 8, 2022
d9c9b68
moved NoneCreatedByIdError
ozer550 Aug 8, 2022
53e77c3
Merge pull request #3471 from ozer550/FEAT_CHANGE_LOG_BROADCASTING
bjester Aug 9, 2022
08e9322
Resolve merge conflicts
bjester Aug 9, 2022
91b927c
Resolve unstable merge conflicts
bjester Aug 9, 2022
035455e
Update websocket consumer to use new task implementation
bjester Aug 9, 2022
97c5661
Merge pull request #3460 from bjester/websockets
bjester Aug 9, 2022
fd04a2f
Resolve merge conflicts; unstable -> websockets
bjester Aug 17, 2022
c571454
Remove imports not caught in merge conflict resolution
bjester Aug 17, 2022
7668279
Merge pull request #3550 from bjester/unstable-to-websockets-2
bjester Aug 17, 2022
bed4154
remould frontend to remove fake task object
ozer550 Aug 22, 2022
80f0a87
Refactor create_change_tracker
ozer550 Aug 22, 2022
15a4014
fix progress after succes
ozer550 Aug 22, 2022
99310c6
Merge pull request #3568 from ozer550/FEAT_TASKS_BROADCASTING
bjester Aug 22, 2022
49da0b7
add recipe for daphne server and change nginx file
ozer550 Aug 31, 2022
959ed30
Resolve merge conflicts in requirements.txt
bjester Sep 2, 2022
86c622b
Merge pull request #3595 from ozer550/FEAT_NGINX_CHANGES
bjester Sep 2, 2022
72e41cd
Resolve makefile conflicts
bjester Sep 2, 2022
8a04104
Merge pull request #3599 from bjester/websockets-unstable-merge
bjester Sep 2, 2022
c439372
change serverSync.js
ozer550 Aug 24, 2022
29e4a66
restructure websocket code
ozer550 Aug 25, 2022
15eaf37
added error handeling for socket functions
ozer550 Aug 31, 2022
aed085d
coHack
ozer550 Sep 2, 2022
9ce6707
Strict created_by_id to not be none
ozer550 Sep 2, 2022
262360b
refactored serverSync.js
ozer550 Sep 6, 2022
55e3be8
remove unnecessary comments
ozer550 Sep 8, 2022
f9874ec
refactor serverSync.js
ozer550 Sep 8, 2022
d83df35
change debounce time
ozer550 Sep 8, 2022
d970e2d
small tweaks
ozer550 Sep 8, 2022
dd4c541
change created_by_id in MaxRev to user.id
ozer550 Sep 8, 2022
370abdb
Merge pull request #3607 from ozer550/FEAT_SERVER_SYNC_JS_CLEANUP
bjester Sep 8, 2022
02e3e5f
Handle merge conflicts
bjester Sep 8, 2022
dc8178e
Merge pull request #3619 from bjester/websockets
bjester Sep 8, 2022
5cbd4ce
Fix bad merging of Makefile changes
bjester Sep 8, 2022
4673ffe
Merge pull request #3622 from bjester/websockets
bjester Sep 8, 2022
64e4fd7
Remove all make dependencies since they weren't being run anyway
bjester Sep 8, 2022
5670713
Reduce procs to better match current production (2), to avoid overloa…
bjester Sep 8, 2022
c06c14d
Merge pull request #3624 from bjester/websockets
bjester Sep 8, 2022
1a4be5f
Fix redis connection trying localhost in production
bjester Sep 9, 2022
20ea181
Merge pull request #3629 from bjester/websockets
bjester Sep 9, 2022
2188634
Added Health Check route for daphne
ozer550 Oct 11, 2022
0db9935
removed repetition of code
ozer550 Oct 11, 2022
1937be3
Merge pull request #3729 from ozer550/FEAT_HEALTH_CHECK_DAPHNE
bjester Oct 11, 2022
df66e8e
Merge branch 'websockets' into websockets-mergedd
bjester Oct 13, 2022
a5f35cf
Merge pull request #3735 from learningequality/websockets-mergedd
bjester Oct 14, 2022
99edf3f
Merge pull request #3815 from learningequality/unstable
bjester Nov 11, 2022
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
27 changes: 20 additions & 7 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,26 @@
# PRODUCTION COMMANDS #########################################
###############################################################
# These are production commands which may be invoked in deployments
altprodserver: NUM_PROCS:=3
altprodserver: NUM_THREADS:=5
altprodserver: collectstatic compilemessages
cd contentcuration/ && gunicorn contentcuration.wsgi:application --timeout=4000 --error-logfile=/var/log/gunicorn-error.log --workers=${NUM_PROCS} --threads=${NUM_THREADS} --bind=0.0.0.0:8081 --pid=/tmp/contentcuration.pid --log-level=debug || sleep infinity
#altprodserver: NUM_PROCS:=3
#altprodserver: NUM_THREADS:=5
#altprodserver: collectstatic compilemessages
# cd contentcuration/ && gunicorn contentcuration.wsgi:application --timeout=4000 --error-logfile=/var/log/gunicorn-error.log --workers=${NUM_PROCS} --threads=${NUM_THREADS} --bind=0.0.0.0:8081 --pid=/tmp/contentcuration.pid --log-level=debug || sleep infinity

altprodserver:
$(MAKE) -j 2 gunicornanddapneserver

gunicornanddapneserver: gunicornserver daphneserver

daphneserver:
cd contentcuration/ && daphne -b 0.0.0.0 -p 8082 contentcuration.asgi:application

gunicornserver: NUM_PROCS:=1
gunicornserver:
cd contentcuration/ && gunicorn contentcuration.wsgi:application --timeout=4000 --error-logfile=/var/log/gunicorn-error.log --workers=${NUM_PROCS} --bind=0.0.0.0:8081 --pid=/tmp/contentcuration.pid --log-level=debug || sleep infinity


contentnodegc:
cd contentcuration/ && python manage.py garbage_collect

prodceleryworkers:
cd contentcuration/ && celery -A contentcuration worker -l info --concurrency=3 --task-events
Expand All @@ -20,9 +36,6 @@ migrate:
python contentcuration/manage.py migrate || true
python contentcuration/manage.py loadconstants

contentnodegc:
python contentcuration/manage.py garbage_collect

filedurations:
python contentcuration/manage.py set_file_duration

Expand Down
3 changes: 3 additions & 0 deletions contentcuration/contentcuration/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ class ContentConfig(AppConfig):
name = 'contentcuration'

def ready(self):
# signals for websockets
import contentcuration.viewsets.websockets.signals # noqa

if settings.AWS_AUTO_CREATE_BUCKET and not is_gcs_backend():
from contentcuration.utils.minio_utils import ensure_storage_bucket_public
ensure_storage_bucket_public()
25 changes: 25 additions & 0 deletions contentcuration/contentcuration/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import django
from channels.auth import AuthMiddlewareStack
from channels.routing import ProtocolTypeRouter
from channels.routing import URLRouter
from django.conf import settings

from contentcuration.viewsets.websockets.routing import http_urlpatterns
from contentcuration.viewsets.websockets.routing import websocket_urlpatterns

django.setup(set_prefix=False)

protocol_config = {
"websocket":
AuthMiddlewareStack(
URLRouter(
websocket_urlpatterns
)
),
}

# production settings to add healthcheck
if not settings.DEBUG:
protocol_config.update(http=URLRouter(http_urlpatterns))

application = ProtocolTypeRouter(protocol_config)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import Dexie from 'dexie';
import sortBy from 'lodash/sortBy';
import { CHANGE_TYPES, IGNORED_SOURCE, TABLE_NAMES } from './constants';
import db from './db';
import { INDEXEDDB_RESOURCES } from './registry';
import { CHANGE_TYPES, IGNORED_SOURCE, TABLE_NAMES } from './constants';

const { CREATED, DELETED, UPDATED, MOVED, PUBLISHED, SYNCED } = CHANGE_TYPES;

Expand Down
43 changes: 26 additions & 17 deletions contentcuration/contentcuration/frontend/shared/data/resources.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Dexie from 'dexie';
import Mutex from 'mutex-js';
import findIndex from 'lodash/findIndex';
import flatMap from 'lodash/flatMap';
import intersection from 'lodash/intersection';
import isArray from 'lodash/isArray';
import isNumber from 'lodash/isNumber';
import isString from 'lodash/isString';
Expand All @@ -14,29 +15,35 @@ import uniqBy from 'lodash/uniqBy';

import { v4 as uuidv4 } from 'uuid';
import {
CHANGE_TYPES,
ACTIVE_CHANNELS,
CHANGES_TABLE,
CHANGE_TYPES,
CHANNEL_SYNC_KEEP_ALIVE_INTERVAL,
COPYING_FLAG,
CURRENT_USER,
CREATION_CHANGE_TYPES,
IGNORED_SOURCE,
LAST_FETCHED,
MAX_REV_KEY,
RELATIVE_TREE_POSITIONS,
TABLE_NAMES,
COPYING_FLAG,
TASK_ID,
CURRENT_USER,
ACTIVE_CHANNELS,
CHANNEL_SYNC_KEEP_ALIVE_INTERVAL,
MAX_REV_KEY,
LAST_FETCHED,
CREATION_CHANGE_TYPES,
TREE_CHANGE_TYPES,
} from './constants';
import applyChanges, { applyMods, collectChanges } from './applyRemoteChanges';
import mergeAllChanges from './mergeChanges';
import db, { channelScope, CLIENTID, Collection } from './db';
import { API_RESOURCES, INDEXEDDB_RESOURCES } from './registry';
import { DELAYED_VALIDATION, fileErrors, NEW_OBJECT } from 'shared/constants';
import client, { paramsSerializer } from 'shared/client';
import { currentLanguage } from 'shared/i18n';
import urls from 'shared/urls';
import { currentLanguage } from 'shared/i18n';
import client, { paramsSerializer } from 'shared/client';

/**
* Task names for which it is only useful to keep the most recent task object
* @type {string[]}
*/
const SINGULAR_TASKS = ['export-channel', 'sync-channel'];

// Number of seconds after which data is considered stale.
const REFRESH_INTERVAL = 5;
Expand Down Expand Up @@ -1847,13 +1854,15 @@ export const Task = new IndexedDBResource({
task.channel_id = task.channel_id.replace('-', '');
}
return this.transaction({ mode: 'rw', source: IGNORED_SOURCE }, () => {
return this.table
.where(this.idField)
.noneOf(tasks.map(t => t[this.idField]))
.delete()
.then(() => {
return this.table.bulkPut(tasks);
});
let deletePromise = Promise.resolve();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this logic is preserving a single task of the type - rather than a single task per type per channel? This might cause weird behaviour if you're editing two channels at once.

let taskDeletes = intersection(
SINGULAR_TASKS,
tasks.map(t => t.task_name)
);
if (taskDeletes.length) {
deletePromise = this.table.filter(t => taskDeletes.includes(t.task_name)).delete();
}
return deletePromise.then(() => this.table.bulkPut(tasks));
});
},
});
Loading