Skip to content

Commit

Permalink
Merge pull request #790 from Expensify/master
Browse files Browse the repository at this point in the history
Update expensify_prod branch
  • Loading branch information
pecanoro authored May 14, 2020
2 parents 8f8ff6f + 5fccd02 commit a461d16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
28 changes: 19 additions & 9 deletions plugins/Jobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -898,11 +898,12 @@ void BedrockJobsCommand::process(SQLite& db) {
// interrupted in a non-fatal way.
//
// Parameters:
// - jobID - ID of the job to requeue
// - delay - Number of seconds to wait before retrying
// - nextRun - datetime of next scheduled run
// - name - An arbitrary string identifier (case insensitive)
// - data - Data to associate with this job
// - jobID - ID of the job to requeue
// - delay - Number of seconds to wait before retrying
// - nextRun - datetime of next scheduled run
// - name - An arbitrary string identifier (case insensitive)
// - data - Data to associate with this job
// - jobPriority - The new priority to set for this job
//
// - FinishJob( jobID, [data] )
//
Expand Down Expand Up @@ -1005,11 +1006,20 @@ void BedrockJobsCommand::process(SQLite& db) {
return;
}

// If this is RetryJob and we want to update the name, let's do that
// If this is RetryJob and we want to update the name and/or priority, let's do that
const string& name = request["name"];
if (!name.empty() && SIEquals(requestVerb, "RetryJob")) {
if (!db.writeIdempotent("UPDATE jobs SET name=" + SQ(name) + " WHERE jobID=" + SQ(jobID) + ";")) {
STHROW("502 Failed to update job name");
if (SIEquals(requestVerb, "RetryJob")) {
if (!name.empty() || request.isSet("jobPriority")) {
if (request.isSet("jobPriority")) {
_validatePriority(request.calc64("jobPriority"));
}
bool success = db.writeIdempotent("UPDATE jobs SET " +
(!name.empty() ? "name=" + SQ(name) + ", " : "") +
(request.isSet("jobPriority") ? "priority=" + SQ(request["jobPriority"]) : "") + " "
"WHERE jobID=" + SQ(jobID) + ";");
if (!success) {
STHROW("502 Failed to update job name/priority");
}
}
}

Expand Down
11 changes: 7 additions & 4 deletions test/tests/jobs/RetryJobTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct RetryJobTest : tpunit::TestFixture {
TEST(RetryJobTest::hasRepeat),
TEST(RetryJobTest::inRunqueuedState),
TEST(RetryJobTest::simplyRetryWithNextRun),
TEST(RetryJobTest::changeName),
TEST(RetryJobTest::changeNameAndPriority),
TEST(RetryJobTest::hasRepeatWithNextRun),
TEST(RetryJobTest::hasRepeatWithDelay),
TEST(RetryJobTest::hasDelayAndNextRun),
Expand Down Expand Up @@ -388,11 +388,12 @@ struct RetryJobTest : tpunit::TestFixture {
ASSERT_EQUAL(result[0][0], nextRun);
}

// Update the name
void changeName() {
// Update the name and priority
void changeNameAndPriority() {
// Create the job
SData command("CreateJob");
command["name"] = "job";
command["jobPriority"] = "500";
STable response = tester->executeWaitVerifyContentTable(command);
string jobID = response["jobID"];

Expand All @@ -407,13 +408,15 @@ struct RetryJobTest : tpunit::TestFixture {
command.methodLine = "RetryJob";
command["jobID"] = jobID;
command["name"] = "newName";
command["jobPriority"] = "1000";
command["nextRun"] = getTimeInFuture(10);
tester->executeWaitVerifyContent(command);

// Confirm the data updated
SQResult result;
tester->readDB("SELECT name FROM jobs WHERE jobID = " + jobID + ";", result);
tester->readDB("SELECT name, priority FROM jobs WHERE jobID = " + jobID + ";", result);
ASSERT_EQUAL(result[0][0], "newName");
ASSERT_EQUAL(result[0][1], "1000");
}

// Repeat should take precedence over nextRun
Expand Down

0 comments on commit a461d16

Please sign in to comment.