8000 feat: Allow setting cron as Server Script frequency by gavindsouza · Pull Request #21142 · frappe/frappe · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Allow setting cron as Server Script frequency #21142

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

Merged
merged 5 commits into from
May 29, 2023

Conversation

gavindsouza
Copy link
Collaborator

Changes

  • New option "Cron" under "Event Frequency"
  • New optional field "Cron Format" - (naming consistent with other usages)

Example

image

@github-actions github-actions bot added the add-test-cases Add test case to validate fix or enhancement label May 27, 2023
@codecov
Copy link
codecov bot commented May 27, 2023

Codecov Report

Merging #21142 (cdef2cc) into develop (c0d5e16) will decrease coverage by 0.14%.
The diff coverage is 80.00%.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #21142      +/-   ##
===========================================
- Coverage    63.79%   63.66%   -0.14%     
===========================================
  Files          764      764              
  Lines        69142    69891     +749     
  Branches      6243     6243              
===========================================
+ Hits         44111    44493     +382     
- Misses       21455    21822     +367     
  Partials      3576     3576              
Flag Coverage Δ
server 68.96% <80.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ankush
Copy link
Member
ankush commented May 28, 2023

Add one test, looks good otherwise 👍

@ankush ankush requested review from ankush and removed request for surajshetty3416 May 29, 2023 12:05
@ankush ankush self-assigned this May 29, 2023
@ankush ankush removed the add-test-cases Add test case to validate fix or enhancement label May 29, 2023
ankush
ankush previously approved these changes May 29, 2023
Copy link
Member
@surajshetty3416 surajshetty3416 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gavindsouza Add description for cron format help (with external link maybe) and also validate the format?

@gavindsouza
Copy link
Collaborator Author

@gavindsouza Add description for cron format help (with external link maybe) and also validate the format?

For the "cron_format" help/description/ext link, do you have any suggestions? I can update it for Server Script and Scheduled Job Type too then. (Else, I think Googling "Cron Format" gives sufficient context too)


Validations are triggered from Scheduled Job (while saving the Server Script) so I think it's covered:

request.js:457 Traceback (most recent call last):
  File "env/lib/python3.10/site-packages/croniter/croniter.py", line 172, in _alphaconv
    return cls.ALPHACONV[index][key]
KeyError: 'p'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "apps/frappe/frappe/app.py", line 53, in application
    response = frappe.api.handle()
  File "apps/frappe/frappe/api.py", line 53, in handle
    return _RESTAPIHandler(call, doctype, name).get_response()
  File "apps/frappe/frappe/api.py", line 69, in get_resp
8000
onse
    return self.handle_method()
  File "apps/frappe/frappe/api.py", line 79, in handle_method
    return frappe.handler.handle()
  File "apps/frappe/frappe/handler.py", line 48, in handle
    data = execute_cmd(cmd)
  File "apps/frappe/frappe/handler.py", line 86, in execute_cmd
    return frappe.call(method, **frappe.form_dict)
  File "apps/frappe/frappe/__init__.py", line 1586, in call
    return fn(*args, **newargs)
  File "apps/frappe/frappe/utils/typing_validations.py", line 33, in wrapper
    return func(*args, **kwargs)
  File "apps/frappe/frappe/desk/form/save.py", line 34, in savedocs
    doc.save()
  File "apps/frappe/frappe/model/document.py", line 316, in save
    return self._save(*args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 368, in _save
    self.run_post_save_methods()
  File "apps/frappe/frappe/model/document.py", line 1100, in run_post_save_methods
    self.run_method("on_update")
  File "apps/frappe/frappe/model/document.py", line 926, in run_method
    out = Document.hook(fn)(self, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1282, in composer
    return composed(self, method, *args, **kwargs)
  File "apps/frappe/frappe/model/document.py", line 1264, in runner
    add_to_return_value(self, fn(self, *args, **kwargs))
  File "apps/frappe/frappe/model/document.py", line 923, in fn
    return method_object(*args, **kwargs)
  File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 23, in on_update
    self.sync_scheduler_events()
  File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 56, in sync_scheduler_events
    setup_scheduler_events(
  File "apps/frappe/frappe/core/doctype/server_script/server_script.py", line 198, in setup_scheduler_events
    ).insert()
  File "apps/frappe/frappe/model/document.py", line 270, in insert
    self._validate()
  File "apps/frappe/frappe/model/document.py", line 544, in _validate
    self._validate_length()
  File "apps/frappe/frappe/model/base_document.py", line 909, in _validate_length
    for fieldname, value in self.get_valid_dict(ignore_virtual=True).items():
  File "apps/frappe/frappe/model/base_document.py", line 312, in get_valid_dict
    field_value = getattr(self, fieldname, None)
  File "apps/frappe/frappe/core/doctype/scheduled_job_type/scheduled_job_type.py", line 58, in next_execution
    return self.get_next_execution()
  File "apps/frappe/frappe/core/doctype/scheduled_job_type/scheduled_job_type.py", line 78, in get_next_execution
    return croniter(
  File "env/lib/python3.10/site-packages/croniter/croniter.py", line 166, in __init__
    self.expanded, self.nth_weekday_of_month = self.expand(expr_format, hash_id=hash_id)
  File "env/lib/python3.10/site-packages/croniter/croniter.py", line 778, in expand
    return cls._expand(expr_format, hash_id=hash_id)
  File "env/lib/python3.10/site-packages/croniter/croniter.py", line 721, in _expand
    t = cls._alphaconv(i, t, expressions)
  File "env/lib/python3.10/site-packages/croniter/croniter.py", line 174, in _alphaconv
    raise CroniterNotAlphaError(
croniter.croniter.CroniterNotAlphaError: [5 4 * * p] is not acceptable

@ankush
Copy link
Member
ankush commented May 29, 2023

#17329

Simplest dx fix is this, "description" idk how hard it would be 😬

@surajshetty3416
Copy link
Member
surajshetty3416 commented May 30, 2023

@gavindsouza, @ankush I was expecting something like following (ref).

Screenshot 2023-05-30 at 10 56 30 AM

ankush added a commit that referenced this pull request May 30, 2023
…#21161)

* feat: Allow setting cron as Server Script frequency

(cherry picked from commit b00aac9)

# Conflicts:
#	frappe/core/doctype/server_script/server_script.json

* test: cron/scheduled scripts

(cherry picked from commit 888209f)

# Conflicts:
#	frappe/core/doctype/server_script/test_server_script.py

* fix: Pass cron format only if frequency is Cron

(cherry picked from commit a1b1679)

* test: save server script

(cherry picked from commit 9f53b56)

* fix: Clear scheduled events if cron_format is changed

(cherry picked from commit cdef2cc)

* chore: Resolve conflicts

---------

Co-authored-by: Gavin D'souza <gavin18d@gmail.com>
Co-authored-by: Ankush Menat <ankush@frappe.io>
frappe-pr-bot pushed a commit that referenced this pull request May 30, 2023
# [14.37.0](v14.36.3...v14.37.0) (2023-05-30)

### Bug Fixes

* add selected on current dropdown-item ([6af79f2](6af79f2))
* added left icon option ([dd86670](dd86670))
* allow default for text and long text when altering table ([#21109](#21109)) ([#21124](#21124)) ([b8c6a7b](b8c6a7b))
* allow setting default in longtext and text columns ([#21089](#21089)) ([#21123](#21123)) ([1f477c2](1f477c2))
* clear & add email template using select group btn ([e367821](e367821))
* create private custom html block ([a552ad9](a552ad9))
* don't mutate notification when getting cc and bcc ([82515b2](82515b2))
* ensure correct return value for `get_values_from_single` ([aee1775](aee1775))
* Exclude Geolocation from "hide empty read-only field" ([#21088](#21088)) ([#21096](#21096)) ([8b76dab](8b76dab))
* made a util to create shadow element ([0427ae0](0427ae0))
* make desk css available i shadow html ([1c085a6](1c085a6))
* make dropdown item label bold ([7bda6a1](7bda6a1))
* make option toggle button smaller ([3aed586](3aed586))
* misc form tour fixes (backport [#21151](#21151)) ([#21152](#21152)) ([2411e66](2411e66))
* offset log cleanup to avoid deadlocks ([#21105](#21105)) ([#21106](#21106)) ([4ba4c94](4ba4c94))
* only show public and user's private blocks in dropdown ([cffa676](cffa676))
* removed html message since we no longer have no ristrictions ([b5a714b](b5a714b))
* setup wizard recursion in routing ([#21101](#21101)) ([#21102](#21102)) ([6c3026f](6c3026f))
* skip form tours on mobile ([#21180](#21180)) ([d87c815](d87c815))
* **workflow:** populate doc from db in apply_workflow ([#21068](#21068)) ([#21093](#21093)) ([a447488](a447488))

### Features

* Allow setting cron as Server Script frequency (backport [#21142](#21142)) ([#21161](#21161)) ([ededac7](ededac7))
* Round QB function ([9d9465a](9d9465a))
* select group button ([e9a474c](e9a474c))
* Truncate QB function ([5d24591](5d24591))
* UI onboarding tours [v14] ([#21114](#21114)) ([181f509](181f509))
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport version-14-hotfix backport to version 14
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0