Skip to content

Instantly share code, notes, and snippets.

@brianv0
Created August 24, 2018 17:29
Show Gist options
  • Save brianv0/b1d058f35825ab68854ab270bf476406 to your computer and use it in GitHub Desktop.
Save brianv0/b1d058f35825ab68854ab270bf476406 to your computer and use it in GitHub Desktop.
Skip Waiting Process Instances
# Find the Stream primary key with process instances you want to skip
# Usually you do this from the web interfaces
stream_id = 254077443L
# Some things you will need along the way.
# This is actually java code you are importing
from org.srs.pipeline.server.sql import DatabaseUtilities
from org.srs.pipeline.server.sql.ProcessInstance import ProcessingStatus
from org.srs.pipeline.server.sql.Stream import StreamStatus
from org.srs.pipeline.server.sql.Process import ProcessType
import sys
# Create new DatabaseUtilities Data Access Object
dbu = DatabaseUtilities()
# Get the Stream object you desire to
stream = dbu.getStream(stream_id)
# Get the process instances
process_instances = dbu.getProcessInstances(stream)
# Determine what the new status you want is (in this case SKIPPED, but usually you want TERMINATED
# You almost always want a "final" state.
new_status = ProcessingStatus.SKIPPED
# Iterate over the process instances in question you want to change
# In some cases, you might want to get the substreams, you'll need a task id
# in that case. Refer to DatabaseUtilities Java code to see what you can do.
for pi in dbu.getProcessInstances(stream):
# Filter them by the status you want, see ProcessingStatus
if pi.status == ProcessingStatus.WAITING:
# Set the new status
print("Setting Status to " + str(new_status) + " for " + str(pi))
dbu.lockAndSetProcessInstanceStatus(pi, status, True)
# Commit right away (usually what you want to do)
dbu.commit()
# When finished with everything, go ahead and close this, but it's not so
# If you forget, it's fine, but it's good to just explicitly clean house
dbu.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment