Add "off" time#59
Conversation
|
✔️ Deploy Preview for vlab-research canceled. 🔨 Explore the source changes: 5a20d17 🔍 Inspect the deploy log: https://app.netlify.com/sites/vlab-research/deploys/61c3ad556af1e0000751a486 |
e0d1380 to
5584818
Compare
5584818 to
701b5ae
Compare
b6dfabe to
49d9c6a
Compare
472f975 to
02760c8
Compare
02760c8 to
fe1f16c
Compare
24a90b7 to
a9b537b
Compare
| CREATE TABLE chatroach.surveys_metadata ( | ||
| surveyid UUID NOT NULL REFERENCES chatroach.surveys(id) ON DELETE CASCADE, | ||
| off_date TIMESTAMPTZ NOT NULL, | ||
| UNIQUE(surveyid) |
There was a problem hiding this comment.
If it's unique and not null, it might be more expresive to just call it a primary key ?
There was a problem hiding this comment.
I would call it survey_metadata -- "data" is already plural, and it's not metadata about all the surveys, each row just refers to one survey!
|
|
||
| function _response (ctx, qa, {question, validation, response, token, followUp}) { | ||
|
|
||
| if (ctx.surveyMetadata && ctx.surveyMetadata.off_date < ctx.timestamp) { |
There was a problem hiding this comment.
Hrm, so even though the table in the database is called "surveys", everywhere here in replybot it's referred to as a "form"... So I would definitely try and keep it consist it within an app.
There was a problem hiding this comment.
Wait, no, nevermind, the metadata applies to the whole survey, not just the form. I take it back!
There was a problem hiding this comment.
Why is it in reference to ctx.timestamp and not response.timestamp?
| const surveyMetadata = await getSurveyMetadata(surveyId) | ||
|
|
||
| const actions = act({form, user}, state, output) | ||
| const actions = act({form, user, surveyMetadata, timestamp}, state, output) |
There was a problem hiding this comment.
I actually don't think act is the right place to put this. The way the event-sourced state machine works, there is exec which does most of the work and creates an intermediate representation called output. That output is then used to transition to the new state via apply and also to generate side effects via act.
But really, when the survey is off, the state should really move to an end state. So the output will need to be different and exec should make the decision.
|
Hey mate, overall looks good! But there is one major thing I left a comment on. |
0678795 to
891096d
Compare
dc2b77f to
60357fd
Compare
|
|
||
|
|
||
| function exec (state, nxt, surveyMetadata) { | ||
| if (surveyMetadata && surveyMetadata.off_date < nxt.timestamp) { |
There was a problem hiding this comment.
Wait, this doesn't make sense to me, we shouldn't respond if the message is a MACHINE_REPORT or a PLATFORM_RESPONSE or an EXTERNAL_EVENT or anything like that.
We can transition to an OFF state, but responding and saying the survey is off should only happen when they write us!
We can, alternatively, make an external_event which is an OFF event, which Dean manages (like timeouts) and then we just react to that event moving everyone into the correct state without having to wait on something else to happen. Maybe that's why it doesn't feel right to find the place now.
efe6a0c to
ac51735
Compare
ac51735 to
5a20d17
Compare
|
@calufa - how we going on this? |
TODO:
dashboard-serverreplybotsurveys_metadatatable