Active Job - How to cancel a scheduled Action Mailer job? - actionmailer

I am using Delayed Job as my queuing backend for Active Job. I have not set up any custom jobs and plan on using Action Mailer to send out scheduled emails asynchronously. How can I prevent a scheduled email from being sent out?
For example, suppose the user can set up email reminders on my application. If the user sets up a reminder for three days in the future, a job will be created. If the user removes that email reminder, the job should be deleted.
Any help would be greatly appreciated!

I decided to approach the problem differently. Instead of scheduling a job and destroying it, I'm just simply scheduling a job.
When the user sets up a reminder for three days in the future, a job is created, just as before. If the user removes the email reminder, the job will still run in three days but won't do anything. Here's an example setup:
# controllers/users_controller.rb
def schedule_reminder
# Get the user that scheduled the reminder
user = User.find_by_id(params[:id])
# Create a reminder for the user
reminder = user.reminders.create(active: true)
# Schedule the reminder to be sent out
SendReminderJob.set(wait_until: 3.days.from_now).perform_later(reminder.id)
end
def unschedule_reminder
reminder = Reminder.find_by_id(params[:reminder_id])
reminder.destroy
end
When the user schedules a reminder, def schedule_reminder is executed. This method creates a reminder and schedules a job that will run in 3 days. It passes in the reminder's ID as an argument so the job can retrieve the reminder when it runs.
When the user deletes the reminder, def unschedule_reminder is executed. This method finds the reminder and deletes it.
Here's what my SendReminderJob job looks like:
# jobs/send_reminder_job.rb
class SendReminderJob < ActiveJob::Base
queue_as :default
def perform(*args)
# Get the reminder
# args.first is the reminder ID
reminder = Reminder.find_by_id(args.first)
# Check if the reminder exists
if !reminder.nil?
# Send the email to the user
end
end
end
When this job runs in three days, it checks to see if the reminder is still set. If it is, it sends out an email to the user. Otherwise, it does nothing. Regardless of whether or not it does anything, this job is deleted after three days!

I created app/models/delayed_backend_mongoid_job.rb.
class DelayedBackendMongoidJob
include Mongoid::Document
field :priority, type: Integer
field :attempts, type: Integer
field :queue, type: String
field :handler, type: String
field :run_at, type: DateTime
field :created_at, type: DateTime
field :updated_at, type: DateTime
end
If you are using ActiveRecord you need to adjust the model file. Then I installed rails_admin and I can view/edit any of the records in that table.
If you have a job scheduled to run in 2 days all you have to do is delete the record and DJ will never pick it up.

Related

Not updateable record set

I have a set of records linked (1 to many) to another table. The data tables are called tblJobs and tblTasks. I want to show 1) whose task is next 2) all the people who are involved in the tasks and 3) how many are done out of the total, and have this display for each Job.
As soon as I create a query that is aggregated (maybe there is a better way) I can no longer amend the main job data. If I try and create a subform with this info, I can't add subforms to continuous records in a form.
I'm doing all this in Access VBA. Here's an example of data seen on form:
tblJob
Company Name: Smiths
Date Start: 01/01/2023
Data finished: Null
Job Completed: Null (Boolean)
tblTask
Task No: 1
Task: Write email
Who: Bob
Completed: Null (Boolean)
Task No: 2
Task: Create Contacts
Who: Fred
Completed: Null
So here I would want to show with the job data that Bob is next, the job involves Bob and Fred and 0 out of 2 task are completed.
Hope that makes sense and many thanks in advance.
I've tried all the data in one record but it locks the data.
Also tried subforms but the screen then only can show one job at a time (no longer Continuous). Currently I am able to show taks completed by placing a subform in a header of a separate form that only appears using OnCurrent. This only shows the data one record at a time. If there is a way to bring this to the main form, that would be great so all records can be seen at once. Let's start a conversation!

Google Sheets - Protect monthly range script needs monthly triggers at specified date and time

I would like to request help with a script Im trying to put together.
Linked is my test spreadsheet including the script I currently have on the second sheet.
The idea is that this sheet will be copied individually to a group of people. Each person will get their own sheet, editable only by them and myself. It does not get shared any further. Each day the person will add a value into the corresponding day's cell.
On the last day of each month at 8pm, I would like to protect (lock) the cells for that month, to stop the person changing any values that they previously entered.
I have put a repeating script together with a function for each month, covering each range. The problem I'm having is creating triggers that will run the function on the required day. If I set a monthly trigger, they will all trigger at the same time at the end of the first month. Ideally I need individual triggers that will run once a year on the specified date and time for each individual function.
Is this possible? Is there a better way of doing this?
I also realise that I will need to give permissions for each function run, and possibly for each individual copy of the sheet I give to said persons. Is there a clever way around that?
Im also thinking another approach would be for the script to trigger each monthly function 'on open' if the relative date has passed. For example, on Open, if Date is Feb 1st, lock January range, and so on.
Any help provided would be greatly appreciated.
(Note: the true sheet I copied my script and layout from starts this section at Column U, which is why I have minimised Columns A-T).
Test Sheet Link: https://docs.google.com/spreadsheets/d/13z8eWpo6oislkGX3USifLWqh5sz3DsJpSY1YyqNLrx8/edit?usp=sharing

How to send email with the list of all people - Power Automate

There are some tutorials that explain how to email someone on their birthday. What I am looking for is to send a single email with the list of all the people who celebrate their birthday that day.
I would like to know how I can send in the body of the email the name of the people who celebrate their birthday on that day.
I have been working on a flow with each of the following steps:
Recurrence:
With this step I send my daily mail every certain hour.
Get items:
I created a sharepoint list where I have the name of the birthday boy, date of birthday (DOB), gender and department.
Initialize variable:
Apply to each
Append to string variable
I add to the Birthdays variable the value that would be the name of the employee whose birthday is that day that is in the sharepoint list
Send an email
In the step of sending an email, I add the previously initialized variable "Birthdays" to the body of the email, which should contain the list of employees whose birthday is that day
I have supported myself with this question made in the Microsoft Power Automate forum but it does not work as it should since I am new to power automate
Error:
At the moment of executing my manual flow I get in the condition as a result false in addition to two errors when I add the variable and send the mail
Can someone give me an orientation in knowing what I am doing wrong in the flow since my mail does not arrive either.
UPDATE:
The value of the Birthdays variable at runtime is as follows:
UPDATE 2:
I have added in Filter Query the following expression formatDateTime(utcNow(),'dd-MM-yyyy') eq 'listColumn' but when executing the manual flow I get that The expression "28-01-2022 eq 'listColumn'" does not It is valid.
Annex error that shows me in the execution of the manual test
UPDATE 3:
The column in the sharepoint list where I am storing the birthday date is called DOB:
Get Items action you should use Filter Query row to search something like: formatDateTime(utcNow(),'dd-MM-yyyy') eq 'listColumn'.(You should have a column in sharepoint containing all user birthdays).
[1]: https://i.stack.imgur.com/Y3s4S.png
Append to String all the emails that you get from GetItems: Email;
Try this one; it should work:
Birthdays eq '#{formatDateTime(utcNow(), 'yyyy-MM-dd')}'

Frequency of script

I am trying to create a powershell script which is based on csv file for metadata, I have defined a column Frequency with a number in it.
for example :
PageName FrequencyMonths Email
Page1 3 security#company.com
Page2 6 HR#company.com
I want to know a way that my powershell runs the code whenever the next frequency date is.
The script I have takes input from csv with above like information and runs a a scheduled task "Daily" to send emails to above people at the.
I want to schedule my PS script to run daily however send email only after 3 months to the security team (every after 3 months) and every 6 months to the HR team
Please suggest
Expected result is to send mails to respective teams based on the frequency of months - using a daily running windows scheduled task
Your current script sets $EmailDate to today + x Month. But everytime the script is run and without saving the value anywhere... You should create another column with the date of the next execution.
If( (get-date).date -le $row.NewColumn ){
# sent the mail
# replace $row.NewColumn with (get-date).Date.AddMonths($Frequency)
}
when you are done export the csv to replace the old one.

Automatic email dependant on date in Microsoft Access

I'm currently creating a database for my work that consists of basic information on the company car fleet. I've created the database and front sheet which consists of variables such as car,c ar color, MOT Date, Tax Date, etc.
I need to somehow have Access detect when a company car's MOT date is due and email someone to notify them that the date is upcoming by comparing today's date with the date entered into the MOT date field.
Something like, if today's date is a week prior to the MOT date, send an email to whoever to notify them that this is due.
I need this to happen automatically, I plan to open and refresh the sheet daily so it doesn't need to be particularly fancy and do it without Access being open, I just need it to perform this task without trawling through pages and pages of data.
You can do this on launch. Just write a query that picks the records you want. Then loop through the query and fire off an email to each person, then make sure you have a field called "EmailSent" that you'll update to True so you don't send them an email the following day (assuming you just want to email them once).
You'll probably just want some VBA along these lines:
Dim db as Database
Dim rec as Recordset
Set db = CurrentDB
Set rec = db.OpenRecordset("SELECT * FROM MyQueryName")
Do while rec.EOF = False
'Loop through each record, send them an email
'Add code to send email here
rec.MoveNext
'Now update the table so these guys don't get emailed again
dim MySQL as String
MySQL = "UPDATE MyQueryName SET EmailSent = 'True'"
DoCmd.RunSQL MySQL
The above is all "aircode" and is untested, but should set you in the right direction.
Just make sure EmailSent = False is a condition in your query.