detect details about scenario run

Adi
Level 1
detect details about scenario run

Hi, 

I would like to create a new scenario that basically just tells me which scenarios were triggered manually in the previous day.

I'm doing it in a python code, and right now I have 2 things i have questions on-

1. I would like to know the real user that triggered the scenario manually, for example even if a scenario has a "run as" option i would like to get both the user that the scenario run as and also the real user who triggered the scenario manually.

the code looks like this right now-

scenario_runs = scenario_obj.get_last_runs(only_finished_runs=True)

for run in scenario_runs:
details = run.get_details()

# Check if the run was manually triggered from the last 24 hours
if run.trigger.get('name') == 'Manual trigger' and run.start_time.date() > last_day:
manually_triggered_runs.append({
'Project' : proj,
'Scenario': scenario_id,
'User' : details.get('scenarioRun', 'User Unknown').get('result', 'User Unknown').get('login', 'User Unknown'),
'Real_user': details.get('realUserLogin', 'User Unknown'),
'Run_ID': run.id,
'Start_Time': str(run.start_time),
'Trigger_Type': run.trigger['name']

so with the login (user field) i get the "run as" user but the "realUserLogin" doesn't work for me..

2. I want to save the results to an hive dataset that only keeps the data of the last day, so in case there's new records of scenarios that were triggered manually everything works fine,  but in case there's no records at some day i want to just delete the records from the dataset but keep it's structure. 
right now im doing- 

df = pd.DataFrame(manually_triggered_runs)

dataset = dataiku.Dataset("Manual_triggered_scenarios_last_day")
dataset.write_with_schema(df)

 

is there any better way i can just delete the old data in the dataset and insert the new records if there is any?

 

Thanks a lot

0 Kudos
1 Reply
Turribeach

Hi, can you please edit your post and change your code to be in a code block (see screen shot below)? As you know padding is key in Python so can't really try your code sample under it's properly formatted. Thanks

 

 

Capture.PNG

0 Kudos