-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adds startup task to cancel previously running tasks #242
Open
purujitgoyal
wants to merge
8
commits into
master
Choose a base branch
from
feature/failed_tasks
base: master
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
67b6792
saves config note status in redis, adds cancel stale notes task on st…
purujitgoyal d525ed8
Adds test
purujitgoyal b9f43f0
try to get config note status from reddit first
purujitgoyal 0a9b142
Merge branch 'master' into feature/failed_tasks
purujitgoyal 9bd6454
adds check for race condition when deploying, move validate group ins…
purujitgoyal 2935ba2
fix validation group test
purujitgoyal bd219a9
Merge branch 'feature/failed_tasks' of github.com:openreview/openrevi…
purujitgoyal 1a036c8
fix more tests
purujitgoyal 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
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
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
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 |
---|---|---|
@@ -1,5 +1,7 @@ | ||
import logging | ||
|
||
import redis | ||
from openreview import openreview | ||
from requests.exceptions import ConnectionError | ||
from urllib3.exceptions import ConnectTimeoutError, RequestError | ||
|
||
|
@@ -105,3 +107,38 @@ def run_deployment( | |
raise self.retry( | ||
exc=exc, countdown=300 * (self.request.retries + 1), max_retries=1 | ||
) | ||
|
||
|
||
@celery.task(name="cancel_stale_notes", track_started=True, bind=True) | ||
def cancel_stale_notes( | ||
self, openreview_baseurl, openreview_username, openreview_password | ||
): | ||
print("Cancelling Stale Notes") | ||
from matcher.service.server import redis_pool | ||
|
||
redis_conn = redis.Redis(connection_pool=redis_pool) | ||
config_notes = redis_conn.hgetall(name="config_notes") | ||
openreview_client = openreview.Client( | ||
baseurl=openreview_baseurl, | ||
username=openreview_username, | ||
password=openreview_password, | ||
) | ||
for note_id, status in config_notes.items(): | ||
if status in ["Running", "Deploying", "Queued"]: | ||
config_note = openreview_client.get_note(note_id) | ||
redis_conn.hset( | ||
name="config_notes", | ||
key=note_id, | ||
value=MatcherStatus.CANCELLED.value, | ||
) | ||
config_note.content["status"] = MatcherStatus.CANCELLED.value | ||
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. Could you add some description in the error message? "Matching run was cancelled, please try again" |
||
config_note.content[ | ||
"error_message" | ||
] = "Matching run was cancelled, please try again or contact support." | ||
openreview_client.post_note(config_note) | ||
print( | ||
"Config Note {} status set to: {}".format( | ||
config_note.id, config_note.content["status"] | ||
) | ||
) | ||
redis_conn.close() |
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
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 |
---|---|---|
@@ -1,2 +1,7 @@ | ||
LOG_FILE='default.log' | ||
OPENREVIEW_BASEURL='http://localhost:3000' | ||
OPENREVIEW_USERNAME='OpenReview.net' | ||
OPENREVIEW_PASSWORD='' | ||
REDIS_ADDR='localhost' | ||
REDIS_PORT=6379 | ||
REDIS_DB=10 |
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
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
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 |
---|---|---|
@@ -1,4 +1,18 @@ | ||
from matcher.service import create_app, create_celery | ||
from celery.signals import worker_ready | ||
|
||
from matcher.service import create_app, create_celery, create_redis | ||
|
||
app = create_app() | ||
celery_app = create_celery(app) | ||
redis_pool = create_redis(app) | ||
|
||
|
||
@worker_ready.connect | ||
def at_start(sender, **kwargs): | ||
with sender.app.connection() as conn: | ||
task_kwargs = { | ||
"openreview_baseurl": sender.app.conf["OPENREVIEW_BASEURL"], | ||
"openreview_username": sender.app.conf["OPENREVIEW_USERNAME"], | ||
"openreview_password": sender.app.conf["OPENREVIEW_PASSWORD"], | ||
} | ||
sender.app.send_task("cancel_stale_notes", kwargs=task_kwargs) |
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 |
---|---|---|
|
@@ -177,6 +177,9 @@ def openreview_context(): | |
"SUPERUSER_LASTNAME": "User", | ||
"SUPERUSER_TILDE_ID": "~Super_User1", | ||
"SUPERUSER_EMAIL": "[email protected]", | ||
"REDIS_ADDR": "localhost", | ||
"REDIS_PORT": 6379, | ||
"REDIS_DB": 10, | ||
} | ||
) | ||
|
||
|
@@ -218,7 +221,7 @@ def celery_includes(): | |
@pytest.fixture(scope="session") | ||
def celery_worker_parameters(): | ||
return { | ||
"queues": ("default", "matching", "deployment", "failure"), | ||
"queues": ("default", "matching", "deployment", "failure", "startup"), | ||
"perform_ping_check": False, | ||
"concurrency": 4, | ||
} | ||
|
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.
@carlosmondra to avoid using the super user to edit the notes, could we have a "matching" user or token? I can modify the invitation so the matching user is writer of all the configuration notes.