Skip to content

Commit

Permalink
Minor fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
rowanseymour committed Oct 1, 2021
1 parent 36042bf commit e64cd47
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 22 deletions.
19 changes: 6 additions & 13 deletions archiver.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,6 @@ func (a *Archive) endDate() time.Time {
return endDate
}

func (a *Archive) coversDate(d time.Time) bool {
end := a.endDate()
return !a.StartDate.After(d) && end.After(d)
}

const lookupActiveOrgs = `
SELECT o.id, o.name, o.created_on, o.is_anon
FROM orgs_org o
Expand Down Expand Up @@ -457,12 +452,12 @@ func EnsureTempArchiveDirectory(path string) error {

testFilePath := filepath.Join(path, ".test_file")
testFile, err := os.Create(testFilePath)
defer testFile.Close()

if err != nil {
return fmt.Errorf("directory '%s' is not writable", path)
}

defer testFile.Close()

err = os.Remove(testFilePath)
return err
}
Expand Down Expand Up @@ -958,13 +953,13 @@ func createArchives(ctx context.Context, db *sqlx.DB, config *Config, s3Client s
})

for _, archive := range archives {
log = logrus.WithFields(logrus.Fields{
log.WithFields(logrus.Fields{
"start_date": archive.StartDate,
"end_date": archive.endDate(),
"period": archive.Period,
"archive_type": archive.ArchiveType,
})
log.Info("starting archive")
}).Info("starting archive")

start := time.Now()

err := createArchive(ctx, db, config, s3Client, archive)
Expand Down Expand Up @@ -1606,9 +1601,7 @@ func ArchiveOrg(ctx context.Context, now time.Time, config *Config, db *sqlx.DB,
return nil, nil, errors.Wrapf(err, "error rolling up archives")
}

for _, m := range monthlies {
created = append(created, m)
}
created = append(created, monthlies...)

// finally delete any archives not yet actually archived
deleted := make([]*Archive, 0, 1)
Expand Down
18 changes: 9 additions & 9 deletions testdb.sql
Original file line number Diff line number Diff line change
Expand Up @@ -159,15 +159,14 @@ CREATE TABLE auth_user (
username character varying(128) NOT NULL
);

DROP TABLE IF EXISTS api_webhookresult CASCADE;
DROP TABLE IF EXISTS api_webhookevent CASCADE;
DROP TABLE IF EXISTS flows_flowpathrecentrun CASCADE;
DROP TABLE IF EXISTS flows_actionlog CASCADE;
DROP TABLE IF EXISTS flows_flowrun CASCADE;
CREATE TABLE flows_flowrun (
id serial primary key,
is_active boolean NOT NULL DEFAULT FALSE,
uuid character varying(36) NOT NULL,
uuid character varying(36) NOT NULL UNIQUE,
responded boolean NOT NULL,
contact_id integer NOT NULL references contacts_contact(id),
flow_id integer NOT NULL references flows_flow(id),
Expand All @@ -180,6 +179,7 @@ CREATE TABLE flows_flowrun (
modified_on timestamp with time zone NOT NULL,
exited_on timestamp with time zone NULL,
submitted_by_id integer NULL references auth_user(id),
status varchar(1) NOT NULL,
exit_type varchar(1) NULL,
delete_reason char(1) NULL
);
Expand Down Expand Up @@ -307,25 +307,25 @@ INSERT INTO flows_flow(id, uuid, name) VALUES
INSERT INTO auth_user(id, username) VALUES
(1, '[email protected]');

INSERT INTO flows_flowrun(id, uuid, responded, contact_id, flow_id, org_id, results, path, events, created_on, modified_on, exited_on, exit_type, parent_id, submitted_by_id) VALUES
(1, '4ced1260-9cfe-4b7f-81dd-b637108f15b9', TRUE, 6, 1, 2, '{}', '[]', '[]', '2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', NULL, NULL),
INSERT INTO flows_flowrun(id, uuid, responded, contact_id, flow_id, org_id, results, path, events, created_on, modified_on, exited_on, status, exit_type, parent_id, submitted_by_id) VALUES
(1, '4ced1260-9cfe-4b7f-81dd-b637108f15b9', TRUE, 6, 1, 2, '{}', '[]', '[]', '2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', 'C', NULL, NULL),
(2, '7d68469c-0494-498a-bdf3-bac68321fd6d', TRUE, 6, 1, 2,
'{"agree": {"category": "Strongly agree", "node_uuid": "a0434c54-3e26-4eb0-bafc-46cdeaf435ac", "name": "Do you agree?", "value": "A", "created_on": "2017-05-03T12:25:21.714339+00:00", "input": "A"}}',
'[{"uuid": "c3d0b417-db75-417c-8050-33776ec8f620", "node_uuid": "10896d63-8df7-4022-88dd-a9d93edf355b", "arrived_on": "2017-08-12T15:07:24.049815+02:00", "exit_uuid": "2f890507-2ad2-4bd1-92fc-0ca031155fca"}]',
'[{"msg": {"urn": "tel:+12076661212", "text": "hola", "uuid": "cf05c58f-31fb-4ce8-9e65-4ecc9fd47cbe", "channel": {"name": "1223", "uuid": "bbfe2e9c-cf69-4d0a-b42e-00ac3dc0b0b8"}}, "type": "msg_created", "step_uuid": "659cdae5-1f29-4a58-9437-10421f724268", "created_on": "2018-01-22T15:06:47.357682+00:00"}]',
'2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', NULL, NULL),
'2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00','2017-08-12 21:11:59.890662+02:00', 'C', 'C', NULL, NULL),
(3, 'de782b35-a398-46ed-8550-34c66053841b', TRUE, 7, 2, 3,
'{"agree": {"category": "Strongly agree", "node_uuid": "084c8cf1-715d-4d0a-b38d-a616ed74e638", "name": "Agree", "value": "A", "created_on": "2017-05-03T12:25:21.714339+00:00", "input": "A"}, "confirm_agree": {"category": "Confirmed Strongly agree", "node_uuid": "a0434c54-3e26-4eb0-bafc-46cdeaf435ab", "name": "Do you agree?", "value": "A", "created_on": "2017-05-03T12:25:21.714339+00:00", "input": "A"}}',
'[{"uuid": "600ac5b4-4895-4161-ad97-6e2f1bb48bcb", "node_uuid": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "arrived_on": "2017-08-12T15:07:24.049815+02:00", "exit_uuid": "8249e2dc-c893-4200-b6d2-398d07a459bc"}]',
'[{"msg": {"urn": "tel:+12076661212", "text": "hola", "uuid": "9ea50923-0888-4596-9a9d-4890994934a9", "channel": {"name": "1223", "uuid": "d6597e08-8285-428c-8e7e-97c68adfa073"}}, "type": "msg_created", "step_uuid": "ae067248-df92-41c8-bb29-92506e984259", "created_on": "2018-01-22T15:06:47.357682+00:00"}]',
'2017-08-10 21:11:59.890662+02:00','2017-08-10 21:11:59.890662+02:00','2017-08-10 21:11:59.890662+02:00', 'C', NULL, 1),
(4, 'de782b35-a398-46ed-8550-34c66053841b', TRUE, 7, 2, 3,
'2017-08-10 21:11:59.890662+02:00','2017-08-10 21:11:59.890662+02:00','2017-08-10 21:11:59.890662+02:00', 'C', 'C', NULL, 1),
(4, 'b3d5a052-77af-4588-b32c-124a7e0e9d6f', TRUE, 7, 2, 3,
'{"agree": {"category": "Disagree", "node_uuid": "084c8cf1-715d-4d0a-b38d-a616ed74e638", "name": "Agree", "value": "B", "created_on": "2017-10-10T12:25:21.714339+00:00", "input": "B"}}',
'[{"uuid": "babf4fc8-e12c-4bb9-a9dd-61178a118b5a", "node_uuid": "accbc6e2-b0df-46cd-9a76-bff0fdf4d753", "arrived_on": "2017-10-12T15:07:24.049815+02:00", "exit_uuid": "8249e2dc-c893-4200-b6d2-398d07a459bc"}]',
'[{"msg": {"urn": "tel:+12076661212", "text": "hi hi", "uuid": "543d2c4b-ff0b-4b87-a9a4-b2d6745cf470", "channel": {"name": "1223", "uuid": "d6597e08-8285-428c-8e7e-97c68adfa073"}}, "type": "msg_created", "step_uuid": "3a5014dd-7b14-4b7a-be52-0419c09340a6", "created_on": "2018-10-12T15:06:47.357682+00:00"}]',
'2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', NULL, NULL),
'2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00','2017-10-10 21:11:59.890662+02:00', 'C', 'C', NULL, NULL),
(6, '6262eefe-a6e9-4201-9b76-a7f25e3b7f29', TRUE, 7, 2, 3, '{}', '[]', '[]',
'2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00', 'C', 4, NULL);
'2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00','2017-12-12 21:11:59.890662+02:00', 'C', 'C', 4, NULL);

INSERT INTO flows_flowpathrecentrun(id, run_id) VALUES
(1, 3);

0 comments on commit e64cd47

Please sign in to comment.