-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…357) * Flag stale runs on app ready in SYNC mode #130 Signed-off-by: Thomas Druez <[email protected]> * Enable redis data persistence using AOF #130 with default policy of fsync every second Signed-off-by: Thomas Druez <[email protected]> * Make sure the job is found before calling delete in Run.delete_task #130 Signed-off-by: Thomas Druez <[email protected]> * Add a sync_with_job method on the run model #130 Synchronise the `self` Run instance with its related RQ Job Signed-off-by: Thomas Druez <[email protected]> * Synchronizes QUEUED and RUNNING Runs with their related Jobs on app ready #130 Signed-off-by: Thomas Druez <[email protected]> * Add unit test for sync_with_job method #130 Signed-off-by: Thomas Druez <[email protected]> * Move the synchronization process in a custom Worker class #130 Signed-off-by: Thomas Druez <[email protected]> * Simplify the synchronization logic #130 Signed-off-by: Thomas Druez <[email protected]> * Reduce the "cleaning lock" ttl from 899 seconds to 60 seconds in ASYNC queue #130 Signed-off-by: Thomas Druez <[email protected]> * Add unit tests for better coverage #130 Signed-off-by: Thomas Druez <[email protected]> * Add CHANGELOG entry #130 Signed-off-by: Thomas Druez <[email protected]>
- Loading branch information
Showing
10 changed files
with
288 additions
and
6 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ | |
**/.aws | ||
**/.ssh | ||
**/.DS_Store | ||
**/.aof | ||
**/venv | ||
**/env | ||
**/bin | ||
|
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
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 |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# http://nexb.com and https:/nexB/scancode.io | ||
# The ScanCode.io software is licensed under the Apache License version 2.0. | ||
# Data generated with ScanCode.io is provided as-is without warranties. | ||
# ScanCode is a trademark of nexB Inc. | ||
# | ||
# You may not use this software except in compliance with the License. | ||
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0 | ||
# Unless required by applicable law or agreed to in writing, software distributed | ||
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR | ||
# CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations under the License. | ||
# | ||
# Data Generated with ScanCode.io is provided on an "AS IS" BASIS, WITHOUT WARRANTIES | ||
# OR CONDITIONS OF ANY KIND, either express or implied. No content created from | ||
# ScanCode.io should be considered or used as legal advice. Consult an Attorney | ||
# for any legal advice. | ||
# | ||
# ScanCode.io is a free software code scanning tool from nexB Inc. and others. | ||
# Visit https:/nexB/scancode.io for support and download. | ||
|
||
from django.apps import apps | ||
from django.conf import settings | ||
|
||
from rq.queue import Queue | ||
from rq.worker import Worker | ||
|
||
scanpipe_app = apps.get_app_config("scanpipe") | ||
|
||
|
||
class ScanCodeIOWorker(Worker): | ||
""" | ||
Modified version of RQ Worker including ScanCode.io customizations. | ||
""" | ||
|
||
def run_maintenance_tasks(self): | ||
""" | ||
Add Runs and Jobs synchronization to the periodic maintenance tasks. | ||
Maintenance tasks should run on first worker startup or every 10 minutes. | ||
During the maintenance, one of the worker will acquire a "cleaning lock" and | ||
will run the registries cleanup. | ||
During that cleanup, started Jobs that haven't sent a heartbeat in the past 90 | ||
seconds (job_monitoring_interval + 60) will be considered failed and will be | ||
moved to the FailedJobRegistry. | ||
This happens when the Job process is killed (voluntary or not) and the heartbeat | ||
is the RQ approach to determine if the job is stills active. | ||
The `sync_runs_and_jobs` will see this Job as failed and will update its related | ||
Run accordingly. | ||
""" | ||
super().run_maintenance_tasks() | ||
|
||
# The Runs and Jobs synchronization needs to be executed after the | ||
# `self.clean_registries()` that takes place in the in the parent | ||
# `super().run_maintenance_tasks()`. | ||
scanpipe_app.sync_runs_and_jobs() | ||
|
||
|
||
class ScanCodeIOQueue(Queue): | ||
""" | ||
Modified version of RQ Queue including ScanCode.io customizations. | ||
""" | ||
|
||
# Reduce the "cleaning lock" ttl from default hardcoded 899 seconds to 60 seconds. | ||
cleaning_lock_ttl = 60 | ||
|
||
def acquire_cleaning_lock(self): | ||
""" | ||
Returns a boolean indicating whether a lock to clean this queue is acquired. | ||
""" | ||
return self.connection.set( | ||
self.registry_cleaning_key, 1, nx=1, ex=self.cleaning_lock_ttl | ||
) |
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
Oops, something went wrong.