Skip to content

Add "off" time#59

Open
calufa wants to merge 8 commits into
mainfrom
feature/add-off-time
Open

Add "off" time#59
calufa wants to merge 8 commits into
mainfrom
feature/add-off-time

Conversation

@calufa

@calufa calufa commented Dec 7, 2021

Copy link
Copy Markdown
Contributor

TODO:

  • add "off" time to surveys
  • add local test suite to dashboard-server
  • add local test suite to replybot
  • add migration script for surveys_metadata table

@calufa
calufa marked this pull request as draft December 7, 2021 22:05
@netlify

netlify Bot commented Dec 7, 2021

Copy link
Copy Markdown

✔️ Deploy Preview for vlab-research canceled.

🔨 Explore the source changes: 5a20d17

🔍 Inspect the deploy log: https://app.netlify.com/sites/vlab-research/deploys/61c3ad556af1e0000751a486

@calufa
calufa force-pushed the feature/add-off-time branch 4 times, most recently from e0d1380 to 5584818 Compare December 12, 2021 00:18
@calufa
calufa force-pushed the feature/add-off-time branch from 5584818 to 701b5ae Compare December 12, 2021 21:05
@calufa
calufa force-pushed the feature/add-off-time branch 2 times, most recently from b6dfabe to 49d9c6a Compare December 13, 2021 03:52
@calufa
calufa force-pushed the feature/add-off-time branch 3 times, most recently from 472f975 to 02760c8 Compare December 13, 2021 23:09
@calufa
calufa force-pushed the feature/add-off-time branch from 02760c8 to fe1f16c Compare December 19, 2021 04:54
Comment thread dashboard-server/queries/responses/response.queries.js
Comment thread dashboard-server/queries/surveys/survey.test.js
Comment thread dashboard-server/queries/surveys/survey.test.js
Comment thread devops/sql/migrate-21.sql
@calufa
calufa requested a review from nandanrao December 20, 2021 19:54
@calufa
calufa marked this pull request as ready for review December 20, 2021 19:54
@calufa
calufa force-pushed the feature/add-off-time branch from 24a90b7 to a9b537b Compare December 20, 2021 19:59
Comment thread dashboard-server/config/index.js
Comment thread devops/sql/migrate-21.sql Outdated
CREATE TABLE chatroach.surveys_metadata (
surveyid UUID NOT NULL REFERENCES chatroach.surveys(id) ON DELETE CASCADE,
off_date TIMESTAMPTZ NOT NULL,
UNIQUE(surveyid)

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.

If it's unique and not null, it might be more expresive to just call it a primary key ?

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.

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!

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.

Sounds good.

Comment thread formcentral/server.go Outdated
Comment thread replybot/lib/typewheels/machine.js Outdated

function _response (ctx, qa, {question, validation, response, token, followUp}) {

if (ctx.surveyMetadata && ctx.surveyMetadata.off_date < ctx.timestamp) {

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.

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.

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.

Wait, no, nevermind, the metadata applies to the whole survey, not just the form. I take it back!

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.

Why is it in reference to ctx.timestamp and not response.timestamp?

Comment thread replybot/lib/typewheels/transition.js Outdated
const surveyMetadata = await getSurveyMetadata(surveyId)

const actions = act({form, user}, state, output)
const actions = act({form, user, surveyMetadata, timestamp}, state, output)

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.

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.

@nandanrao

Copy link
Copy Markdown
Contributor

Hey mate, overall looks good! But there is one major thing I left a comment on.

@calufa
calufa force-pushed the feature/add-off-time branch 6 times, most recently from 0678795 to 891096d Compare December 22, 2021 22:18
Comment thread replybot/lib/typewheels/transition.js
@calufa
calufa force-pushed the feature/add-off-time branch 3 times, most recently from dc2b77f to 60357fd Compare December 22, 2021 22:29


function exec (state, nxt, surveyMetadata) {
if (surveyMetadata && surveyMetadata.off_date < nxt.timestamp) {

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.

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.

@calufa
calufa force-pushed the feature/add-off-time branch 3 times, most recently from efe6a0c to ac51735 Compare December 22, 2021 22:42
@calufa
calufa force-pushed the feature/add-off-time branch from ac51735 to 5a20d17 Compare December 22, 2021 22:57
@nandanrao

Copy link
Copy Markdown
Contributor

@calufa - how we going on this?

@calufa

calufa commented Jan 6, 2022

Copy link
Copy Markdown
Contributor Author

@calufa calufa mentioned this pull request Jan 7, 2022
9 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants