Skip to content

Commit

Permalink
set last_successful_status
Browse files Browse the repository at this point in the history
  • Loading branch information
terrywbrady committed Aug 9, 2024
1 parent 49eeb16 commit 7a35a60
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 25 deletions.
20 changes: 17 additions & 3 deletions src/main/java/org/cdlib/mrt/zk/Job.java
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,23 @@ public static Job createJob(ZooKeeper client, String bid, int priority, JSONObje
}
}

public JSONObject statusObject(IngestState status) {
JSONObject jobj = super.statusObject(status);
jobj.put(MerrittJsonKey.LastSuccessfulStatus.key(), JSONObject.NULL);
public JSONObject statusObject(JSONObject statj, IngestState status) {
JSONObject jobj = super.statusObject(statj, status);
if (!jobj.has(MerrittJsonKey.LastSuccessfulStatus.key())) {
jobj.put(MerrittJsonKey.LastSuccessfulStatus.key(), JSONObject.NULL);
}

JobState oldstat = null;
if (statj.has(MerrittJsonKey.Status.key())) {
oldstat = JobState.valueOf(statj.get(MerrittJsonKey.Status.key()).toString());
}

if (oldstat == null) {
} else if (status == JobState.Failed || status == JobState.Deleted) {
} else if (status == oldstat) {
} else {
jobj.put(MerrittJsonKey.LastSuccessfulStatus.key(), statj.get(MerrittJsonKey.Status.key()));
}
jobj.put(MerrittJsonKey.RetryCount.key(), retryCount);
return jobj;
}
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/org/cdlib/mrt/zk/QueueItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,8 @@ public void createOrSetData(ZooKeeper client, ZKKey key, Object data) throws Kee
}
}

public JSONObject statusObject(IngestState status) {
JSONObject jobj = new JSONObject();
public JSONObject statusObject(JSONObject statj, IngestState status) {
JSONObject jobj = statj == null ? new JSONObject() : new JSONObject(statj.toString());
jobj.put(MerrittJsonKey.Status.key(), status.name());
jobj.put(MerrittJsonKey.LastModified.key(), QueueItemHelper.now());
return jobj;
Expand All @@ -255,7 +255,8 @@ public void setStatus(ZooKeeper client, IngestState status, String message) thro
}
}
String statpath = makePath(ZKKey.STATUS);
JSONObject json = statusObject(status);
JSONObject oldjson = QueueItemHelper.exists(client, statpath) ? jsonProperty(client, ZKKey.STATUS) : new JSONObject();
JSONObject json = statusObject(oldjson, status);
if (message == null) {
message = "";
}
Expand Down
22 changes: 15 additions & 7 deletions src/main/ruby/lib/merritt_zk_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,13 +142,21 @@ def self.create_job(zk, bid, data, priority: 5, identifiers: {}, metadata: {})
job
end

def status_object(status)
{
status: status.name,
last_successful_status: nil,
last_modified: Time.now.to_s,
retry_count: @retry_count
}
def status_object(oldstat, status)
oldstatus = oldstat.nil? ? nil : oldstat[:status]
jobj = super(oldstat, status)

jobj[:last_successful_status] = nil unless jobj.key?(:last_successful_status)

if oldstatus.nil?
elsif status.nil?
elsif status == MerrittZK::JobState::Failed || status == MerrittZK::JobState::Deleted
elsif status.name == oldstatus
else
jobj[:last_successful_status] = oldstatus
end
jobj[:retry_count] = @retry_count
jobj
end

def self.acquire_job(zk, state)
Expand Down
13 changes: 9 additions & 4 deletions src/main/ruby/lib/merritt_zk_queue_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,22 @@ def self.create_id(zk, prefix)
path.split('/')[-1]
end

def status_object(status)
{
status: status.name,
def status_object(oldstat, status)
defs = {
last_modified: Time.now.to_s
}
stat = oldstat.nil? ? defs : oldstat
stat[:status] = status.name
stat
end

def set_status(zk, status, message = '')
return if status == @status

json = status_object(status)
oldjson = nil
oldjson = json_property(zk, ZkKeys::STATUS) if zk.exists?("#{path}/#{ZkKeys::STATUS}")

json = status_object(oldjson, status)
json[:message] = message
data = QueueItem.serialize(json)
if @status.nil?
Expand Down
16 changes: 8 additions & 8 deletions test-cases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ create_job_state_change:
/jobs/jid0/priority: 5
/jobs/jid0/space_needed: 0
/jobs/jid0/status:
last_successful_status: null
last_successful_status: Pending
status: Estimating
last_modified: now
retry_count: 0
Expand All @@ -187,7 +187,7 @@ load_job_state_change:
/jobs/jid0/priority: 5
/jobs/jid0/space_needed: 0
/jobs/jid0/status:
last_successful_status: null
last_successful_status: Pending
status: Estimating
last_modified: now
retry_count: 0
Expand All @@ -212,7 +212,7 @@ acquire_pending_job:
/jobs/jid0/priority: 5
/jobs/jid0/space_needed: 0
/jobs/jid0/status:
last_successful_status: null
last_successful_status: Pending
status: Estimating
last_modified: now
retry_count: 0
Expand Down Expand Up @@ -251,7 +251,7 @@ acquire_lowest_priority_job:
/jobs/jid1/priority: 2
/jobs/jid1/space_needed: 0
/jobs/jid1/status:
last_successful_status: null
last_successful_status: Pending
status: Estimating
last_modified: now
retry_count: 0
Expand Down Expand Up @@ -301,7 +301,7 @@ job_happy_path:
/jobs/jid1/priority: 2
/jobs/jid1/space_needed: 0
/jobs/jid1/status:
last_successful_status: null
last_successful_status: Notify
status: Completed
last_modified: now
retry_count: 0
Expand Down Expand Up @@ -341,7 +341,7 @@ batch_happy_path:
/jobs/jid1/priority: 2
/jobs/jid1/space_needed: 0
/jobs/jid1/status:
last_successful_status: null
last_successful_status: Notify
status: Completed
last_modified: now
retry_count: 0
Expand All @@ -367,7 +367,7 @@ batch_failure:
/jobs/jid1/priority: 2
/jobs/jid1/space_needed: 0
/jobs/jid1/status:
last_successful_status: null
last_successful_status: Recording
status: Deleted
last_modified: now
retry_count: 0
Expand All @@ -393,7 +393,7 @@ batch_recovery:
/jobs/jid1/priority: 2
/jobs/jid1/space_needed: 0
/jobs/jid1/status:
last_successful_status: null
last_successful_status: Notify
status: Completed
last_modified: now
retry_count: 1
Expand Down

0 comments on commit 7a35a60

Please sign in to comment.