Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/nursix/eden
Browse files Browse the repository at this point in the history
  • Loading branch information
flavour committed Nov 25, 2019
2 parents dc8eeec + 3d65b88 commit 4e5d82a
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 58 deletions.
37 changes: 19 additions & 18 deletions modules/s3/s3task.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,11 @@ def __init__(self):
# Instantiate Scheduler
try:
from gluon.scheduler import Scheduler
except:
except ImportError:
# Warning should already have been given by eden_update_check.py
self.scheduler = None
else:
self.scheduler = Scheduler(current.db,
tasks,
migrate=migrate)
self.scheduler = Scheduler(current.db, tasks, migrate=migrate)

# -------------------------------------------------------------------------
def configure_tasktable_crud(self,
Expand Down Expand Up @@ -397,7 +395,8 @@ def schedule_task(self,
return task_id

# -------------------------------------------------------------------------
def _duplicate_task_exists(self, task, args, vars):
@staticmethod
def _duplicate_task_exists(task, args, vars):
"""
Checks if given task already exists in the Scheduler and both coincide
with their execution time
Expand All @@ -410,10 +409,10 @@ def _duplicate_task_exists(self, task, args, vars):
db = current.db
ttable = db.scheduler_task

_args = json.dumps(args)
args_json = json.dumps(args)

query = ((ttable.function_name == task) & \
(ttable.args == _args) & \
(ttable.args == args_json) & \
(ttable.status.belongs(["RUNNING", "QUEUED", "ALLOCATED"])))
jobs = db(query).select(ttable.vars)
for job in jobs:
Expand All @@ -423,7 +422,8 @@ def _duplicate_task_exists(self, task, args, vars):
return False

# -------------------------------------------------------------------------
def _is_alive(self):
@staticmethod
def _is_alive():
"""
Returns True if there is at least 1 active worker to run scheduled tasks
- run from the main request
Expand All @@ -438,19 +438,19 @@ def _is_alive(self):
# return False

db = current.db
cache = current.response.s3.cache
now = datetime.datetime.now()
table = db.scheduler_worker

now = datetime.datetime.now()
offset = datetime.timedelta(minutes=1)
table = db.scheduler_worker

query = (table.last_heartbeat > (now - offset))
cache = current.response.s3.cache
worker_alive = db(query).select(table.id,
limitby=(0, 1),
cache=cache).first()
if worker_alive:
return True
else:
return False
limitby = (0, 1),
cache = cache,
).first()

return True if worker_alive else False

# -------------------------------------------------------------------------
@staticmethod
Expand All @@ -473,7 +473,8 @@ def reset(task_id):
# =========================================================================
# Functions run within the Task itself
# =========================================================================
def authenticate(self, user_id):
@staticmethod
def authenticate(user_id):
"""
Activate the authentication passed from the caller to this new request
- run from within the task
Expand Down
88 changes: 48 additions & 40 deletions modules/templates/SAMBRO/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,8 @@ def onaccept(form):
def customise_msg_rss_channel_controller(**attr):

s3 = current.response.s3
table = current.s3db.msg_rss_channel
type = current.request.get_vars.get("type", None)
if type == "cap":
channel_type = current.request.get_vars.get("type", None)
if channel_type == "cap":
# CAP RSS Channel
s3.filter = (FS("type") == "cap")
s3.crud_strings["msg_rss_channel"] = Storage(
Expand All @@ -208,7 +207,7 @@ def custom_postp(r, output):

if r.interactive and isinstance(output, dict):
# Modify Open Button
if type == "cap":
if channel_type == "cap":
# CAP RSS Channel
table = r.table
query = (table.deleted == False)
Expand All @@ -218,43 +217,51 @@ def custom_postp(r, output):
restrict_e = [str(row.id) for row in rows if not row.enabled]
restrict_d = [str(row.id) for row in rows if row.enabled]

s3.actions = [dict(label=s3_str(T("Open")),
_class="action-btn edit",
url=URL(args=["[id]", "update"],
vars={"type": "cap"}),
),
dict(label=s3_str(T("Delete")),
_class="delete-btn",
url=URL(args=["[id]", "delete"],
vars={"type": "cap"}),
),
dict(label=s3_str(T("Subscribe")),
_class="action-btn",
url=URL(args=["[id]", "enable"],
vars={"type": "cap"}),
restrict = restrict_e),
dict(label=s3_str(T("Unsubscribe")),
_class="action-btn",
url = URL(args = ["[id]", "disable"],
vars={"type": "cap"}),
restrict = restrict_d),
]
s3.actions = [{"label": s3_str(T("Open")),
"_class": "action-btn edit",
"url": URL(args = ["[id]", "update"],
vars = {"type": "cap"},
),
},
{"label": s3_str(T("Delete")),
"_class": "delete-btn",
"url": URL(args = ["[id]", "delete"],
vars = {"type": "cap"},
),
},
{"label": s3_str(T("Subscribe")),
"_class": "action-btn",
"url": URL(args = ["[id]", "enable"],
vars = {"type": "cap"},
),
"restrict": restrict_e,
},
{"label": s3_str(T("Unsubscribe")),
"_class": "action-btn",
"url": URL(args = ["[id]", "disable"],
vars = {"type": "cap"},
),
"restrict": restrict_d
},
]

if not current.s3task._is_alive():
# No Scheduler Running
s3.actions += [dict(label=s3_str(T("Poll")),
_class="action-btn",
url = URL(args = ["[id]", "poll"],
vars={"type": "cap"}),
restrict = restrict_d)
]
s3.actions.append({"label": s3_str(T("Poll")),
"_class": "action-btn",
"url": URL(args = ["[id]", "poll"],
vars = {"type": "cap"},
),
"restrict": restrict_d,
})

if "form" in output and current.auth.s3_has_role("ADMIN"):
# Modify Add Button
add_btn = A(T("Add CAP Feed"),
_class="action-btn",
_href=URL(args=["create"],
vars={"type": "cap"})
_class = "action-btn",
_href = URL(args = ["create"],
vars = {"type": "cap"},
),
)
output["showadd_btn"] = add_btn

Expand Down Expand Up @@ -766,7 +773,6 @@ def custom_msg_render(resource, data, meta_data, format=None):
notify_on = meta_data["notify_on"]
last_check_time = meta_data["last_check_time"]
rows = data["rows"]
rfields = data["rfields"]
output = {}
upd = [] # upd as the created alerts might be approved after some time, check is also done

Expand Down Expand Up @@ -1025,9 +1031,9 @@ def pr_subscription_filter_row_options():

if current.request.get_vars["option"] == "manage_recipient" and \
(has_role("ALERT_EDITOR") or has_role("ALERT_APPROVER")):
# Admin based subscription
query = (stable.deleted != True) & \
(stable.owned_by_group != None)
# Admin based subscription
query = (stable.deleted != True) & \
(stable.owned_by_group != None)
else:
# Self Subscription
query = (stable.deleted != True) & \
Expand All @@ -1038,11 +1044,13 @@ def pr_subscription_filter_row_options():
rows = db(query).select(stable.filter_id,
ftable.query,
left=left)

filter_options = {}

if len(rows) > 0:
T = current.T
etable = s3db.event_event_type
ptable = s3db.cap_warning_priority
filter_options = {}
from s3 import IS_ISO639_2_LANGUAGE_CODE
languages_dict = dict(IS_ISO639_2_LANGUAGE_CODE.language_codes())
for row in rows:
Expand Down Expand Up @@ -1086,7 +1094,7 @@ def pr_subscription_filter_row_options():
else:
filter_options[row["pr_subscription.filter_id"]] = T("No filters")

return filter_options
return filter_options

# -------------------------------------------------------------------------
def get_html_email_content(row, ack_id=None, system=True):
Expand Down

0 comments on commit 4e5d82a

Please sign in to comment.