Skip to content

Commit

Permalink
update db w/ checksum value
Browse files Browse the repository at this point in the history
  • Loading branch information
dchhabda committed Dec 19, 2024
1 parent 094984e commit dcd510b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
3 changes: 3 additions & 0 deletions pybossa/model/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# along with PYBOSSA. If not, see <http://www.gnu.org/licenses/>.

from sqlalchemy import Integer, Boolean, Float, UnicodeText, Text, DateTime
from sqlalchemy import String
import sqlalchemy
from sqlalchemy.schema import Column, ForeignKey, Index
from sqlalchemy.orm import relationship, backref
Expand Down Expand Up @@ -65,6 +66,8 @@ class Task(db.Model, DomainObject):
gold_answers = Column(JSONB)
#: Task.expiration field to determine when a task should no longer be scheduled. As UTC timestamp without timezone
expiration = Column(DateTime, nullable=True)
#: Task.dup_checksum field to contain checksum for duplicate check
dup_checksum = Column(String(64), nullable=True)

task_runs = relationship(TaskRun, cascade='all, delete, delete-orphan', backref='task')

Expand Down
4 changes: 1 addition & 3 deletions pybossa/repositories/task_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,7 @@ def save(self, element, clean_project=True):
# set task default expiration
if element.__class__.__name__ == "Task":
element.expiration = get_task_expiration(element.expiration, make_timestamp())
checksum = generate_checksum(element)
current_app.logger.info("Project %d duplicate checksum %s", element.project_id, checksum)
# element.checksum = generate_checksum(element) TODO: upon task table updated
element.dup_checksum = generate_checksum(element)
self.db.session.add(element)
self.db.session.commit()
if clean_project:
Expand Down
4 changes: 3 additions & 1 deletion pybossa/task_creator_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,6 @@ def generate_checksum(task):
current_app.logger.info("Project %d duplicate check fields %s", task.project_id, str(list(checksum_fields)))
checksum = hashlib.sha256()
checksum.update(json.dumps(checksum_payload, sort_keys=True).encode("utf-8"))
return checksum.hexdigest()
checksum_value = checksum.hexdigest()
current_app.logger.info("Project %d duplicate checksum %s", project.id, checksum_value)
return checksum_value

0 comments on commit dcd510b

Please sign in to comment.