Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional overwrite parameter to CreateJob and CreateJobs #916

Merged
merged 6 commits into from Oct 27, 2020

Conversation

alex-mechler
Copy link
Contributor

@alex-mechler alex-mechler commented Oct 26, 2020

@iwiznia can you review please?

Part of https://github.com/Expensify/Expensify/issues/143805

This adds an optional parameter to CreateJob and CreateJobs where we will not overwrite any data when when attempting to create a unique job that already exists. This optional parameter is assumed to be true when not included to not break any existing behavior

Tests

Added a new automated test, will be further tested in followup prs

Tested in a full flow with https://github.com/Expensify/Web-Expensify/pull/29514

plugins/Jobs.cpp Outdated
@@ -402,6 +402,8 @@ void BedrockJobsCommand::process(SQLite& db) {
// - jobPriority - High priorities go first (optional, default 500)
// - unique - if true, it will check that no other job with this name already exists, if it does it will
// return that jobID
// - overwrite - if true, and unique is true, it will overwrite the existing job with the new jobs data
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// - overwrite - if true, and unique is true, it will overwrite the existing job with the new jobs data
// - overwrite - Only applicable when submit is is true. When set to true it will overwrite the existing job with the new jobs data

plugins/Jobs.cpp Outdated
"WHERE jobID = " + SQ(updateJobID) + ";"))
{
STHROW("502 update query failed");
if (!SContains(job, "overwrite") || job["overwrite"] == "true") {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you also want to check if overwrite is == and treat it as true too?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm not quite following. What would we check if overwrite is == to?

Copy link
Contributor

Choose a reason for hiding this comment

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

Damn sorry, I mean is equal to ''

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah good catch, will add that

// Update the existing job.
if(!db.writeIdempotent("UPDATE jobs SET "
"repeat = " + SQ(SToUpper(job["repeat"])) + ", " +
"data = JSON_PATCH(data, " + safeData + "), " +
Copy link
Contributor

Choose a reason for hiding this comment

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

hmmm you sure about PATCH? Don't we want to replace the whole data?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the same query as before, just indented. I agree it probably should not be a PATCH, but I don't want to change existing behavior (in case any relies on this)

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh... 🤦 you are right

@alex-mechler
Copy link
Contributor Author

Updated

@iwiznia
Copy link
Contributor

iwiznia commented Oct 27, 2020

All looks good, I did not hit the merge button because it seems real tests have not been done yet... feel free to merge when you do.

@alex-mechler
Copy link
Contributor Author

Ah, this was tested with https://github.com/Expensify/Web-Expensify/pull/29514, going to hit the merge button

@alex-mechler alex-mechler merged commit aca9111 into master Oct 27, 2020
@alex-mechler alex-mechler deleted the amechler-overwrite-create-job branch October 27, 2020 17:52
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.

None yet

2 participants