This repository has been archived by the owner on Sep 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 128
[QUAD] Enhancement: Reactivating ftrack user while he has active deadline jobs #6298
Open
ccaillot
wants to merge
1
commit into
ynput:develop
Choose a base branch
from
quadproduction:enhancement/reactivating_ftrack_user_while_he_has_active_deadline_jobs
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
98 changes: 98 additions & 0 deletions
98
openpype/modules/ftrack/event_handlers_server/event_keep_user_active_for_deadline.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import ftrack_api | ||
from openpype_modules.ftrack.lib import BaseEvent | ||
from openpype.modules import ModulesManager | ||
|
||
|
||
class KeepUserActiveForDeadline(BaseEvent): | ||
|
||
def launch(self, session, event): | ||
"""Ensure the user stays active while having ongoing job(s) in the Deadline.""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (87 > 79 characters) |
||
if not event.get('data'): | ||
return | ||
|
||
entities_info = event['data'].get('entities') | ||
if not entities_info: | ||
return | ||
|
||
entity_info = entities_info[0] | ||
# check if a user has been deactivated | ||
if entity_info.get('entity_type') != "User": | ||
return | ||
if entity_info.get('action', "") != "update": | ||
return | ||
if "isactive" not in entity_info.get('changes', {}): | ||
return | ||
if entity_info['changes']['isactive'].get('new') != False: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. comparison to False should be 'if cond is not False:' or 'if cond:' |
||
return | ||
|
||
user = session.get('User', entity_info.get('entityId')) | ||
if not user: | ||
return | ||
|
||
job_ids = self.get_user_active_deadline_jobs(user['username']) | ||
if not job_ids: | ||
return | ||
|
||
# Re-activate the account | ||
user['is_active'] = True | ||
session.commit() | ||
self.log.info("the user {} has been re-activated".format(user['username'])) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (83 > 79 characters) |
||
|
||
# Return the issue message form | ||
items = [ | ||
{ | ||
"type": "label", | ||
"value": "#Warning: The user has been re-activated!" | ||
}, | ||
{ | ||
"type": "label", | ||
"value": "The following jobs from this user are currently active " | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. line too long (82 > 79 characters) |
||
"on deadline:\n{}".format("\n".join(job_ids)) | ||
}, | ||
{ | ||
"type": "label", | ||
"value": "Please try later when all the jobs are done." | ||
} | ||
] | ||
|
||
self.show_interface( | ||
items, | ||
title="The User Must Remain Active", | ||
event=event, | ||
submit_btn_label="I will try later!" | ||
) | ||
return True | ||
|
||
def get_user_active_deadline_jobs(self, user): | ||
"""Get all active deadline jobs of the user | ||
""" | ||
manager = ModulesManager() | ||
deadline_module = manager.modules_by_name["deadline"] | ||
deadline_url = deadline_module.deadline_urls["default"] | ||
|
||
if not deadline_module.enabled or not deadline_url: | ||
self.log.info("Deadline not enabled or URL not found, skipping.") | ||
return None | ||
|
||
requested_arguments = { | ||
"States": "Active" | ||
} | ||
|
||
jobs = deadline_module.get_deadline_data( | ||
deadline_url, | ||
"jobs", | ||
log=None, | ||
**requested_arguments | ||
) | ||
|
||
user_jobs = [] | ||
for job in jobs: | ||
if job['Props']['Env'].get('FTRACK_API_USER') == user: | ||
user_jobs.append(job['_id']) | ||
|
||
return user_jobs | ||
|
||
|
||
def register(session): | ||
"""Register plugin. Called when used as an plugin.""" | ||
KeepUserActiveForDeadline(session).register() |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'ftrack_api' imported but unused