I saw 2 discussions on bi-weekly job. However, both don't have a precise solution to this technical requirement. That's why, I am starting this thread.
I have a requirement to run a DAG every alternate Friday at 5 PM. So, if I start my DAG on 19 Mar, 2021, then it should run on the 19th of Mar, 2021 and the subsequent runs should happen on alternate Fridays. This would mean that after 19th Mar, 2021 the next run should happen on 02 Apr, 2021. How can I achieve it?
Thanks in advance!
After lot of deliberations and help from many in the community, I got the answer from AirFlow slack community.
def _skipcondition(execution_date, **_):
first_valid_friday = datetime(2021, 4, 9)
return (execution_date - first_valid_friday).days % 14 == 0
with DAG(dag_id='fortnightSchedule',default_args = default_args, schedule_interval = "0 17 * * 5", catchup=False) as dag:
check_valid_friday = ShortCircuitOperator(
task_id="check_if_correct_friday",
python_callable=_skipcondition,
provide_context=True,
)
rest_of_tasks = DummyOperator(
task_id="dependent_dummy",
)
check_valid_friday >> rest_of_tasks
Its a simple function that returns True when the number of days between execution date and first execution date is divisible by 14.
Thanks for your help.
I do not think there is any straightforward way to do this, but I can provide some valid approaches by which you can do it.
Option 1
Set the schedule to 0 17 * * 5 - which translates to At 17:00 on Friday.
Use a BranchPythonOperator to get the last dag successful branch run date from airflow variables and check if it is 14 days from the current run date.
The date will be stored as an airflow variable and updated only when the true branch (alternate Friday runs) succeed.
If yes, continue the rest of the DAG, else, skip the rest of the tasks. An example of how to implement this is given in the above-mentioned link.
Option 2
Set the schedule to something like 0 17 1,14 * 5 - which translates to At 17:00 on day-of-month 1 and 14 and on Friday. This will run twice a month.
Note: Option 1 is preferred over Option 2 as it will help tackle the requirement as expected.
Hope these help!
I think you can use datetime.timedelta function.
you can execute DAG after 14days based on start_date.
using this you can execute DAG below day.
2021-03-19
2021-04-02
2021-04-16
2021-04-16
....
this can be the example.
import datetime
dag = Dag(
dag_id="bi_weekly_dag",
schedule_interval=datetime.timedelta(days=14)
start_date=datetime.datetime(year=2021, month=4, day=19)
)
Related
Client give 100 task to employee.
Employee complete 50 task in 1 day
20 task in 2 days
15 task in 3 days
4 task in 4 days
5 taak in 6 days
6 task in 10 days.
Now I want to know on a average how many days employee will take to complete for 1 task
Need formula for this query..
Assuming tasks are not completed in parallel (i.e. days are mutually exclusive with respect to completing/working on tasks), average days per task = 0.26:
=SUM(B2:B7)/SUM(A2:A7)
This is where the solution should terminate - however, I provide a number of checks/alternative approaches which serve to demonstrate (unequivocally) the veracity of the above function...
checks
check 1
The same can be derived using the 'weighted average calculation:
=SUM((B2:B7/A2:A7)*A2:A7)/SUM(A2:A7)
check 2
Intuitively, if each task takes ~0.26 days to complete, and there are 100 tasks, then the total duration (days) ~= 26: summing column B gives just that:
check 3
If still unconvinced, you can calculate the average days per task for each category/type (i.e. for those that take 1,2,3,.., 10 days to complete):
=B2:B7/A2:A7
Then expand these out using sequence / other method:
=SEQUENCE(1,A2,G2,0)
Again, this yields 0.26 and which should confirm (unequivocally) the veracity of the simple/direct ratio...
Ta
My crontab entry is like below:
30 1 9-29 * 1-6 test.sh
I want my cronjob to run at 1:30 AM GMT on dates from 9 to 29 from Monday to Saturday. However, my script (test.sh) is being executed on Sundays also.
I gave the range 1-6 (meaning 1 for Monday and 6 for Saturday).
Can someone tell me where am I wrong or what can be done so that the script does not run on Sundays?
I already achieved to get calendar days:
*** Test Cases ***
Get Date & Time on Banner
${date_var} get text ${LOCATOR}
log ${date_var} console=yes
${time} Get Time NOW
${plus} Add Time To Date ${time} 14 days
${convert} Convert Date ${plus} result_format=%Y-%m-%d %H:%M
log ${convert} console=yes
Should Be Equal ${date_var} ${convert} ELSE Log console=yes
Output is Pass:
2020-07-10 10:24
2020-09-16 16:30
Could someone help how to achieve calc against system date for business days (excluding weekdays/holidays)?
I need help understanding why I am getting the wrong answer for Problem 19 of Project Euler.
The problem is:
You are given the following information, but you may prefer to do some research for yourself.
1 Jan 1900 was a Monday.
Thirty days has September,
April, June and November.
All the rest have thirty-one,
Saving February alone,
Which has twenty-eight, rain or shine.
And on leap years, twenty-nine.
A leap year occurs on any year evenly divisible by 4, but not on a century unless it is divisible by 400.
How many Sundays fell on the first of the month during the twentieth century (1 Jan 1901 to 31 Dec 2000)?
#rm(list=ls())
days=seq(from=as.Date("1900/1/1"), to=as.Date("2000/12/31"), by="month")
firstSundays=days[weekdays(as.Date(days))=="Sunday"&months(as.Date(days))=="January"]
length(firstSundays)
The answer it gives me is 14 and when I look at firstSundays it gives me:
[1] "1905-01-01" "1911-01-01" "1922-01-01" "1928-01-01" "1933-01-01"
[6] "1939-01-01" "1950-01-01" "1956-01-01" "1961-01-01" "1967-01-01"
[11] "1978-01-01" "1984-01-01" "1989-01-01" "1995-01-01"
I don't understand what is going on here. Could someone please explain? I am fairly new to R and I'm not sure what I am doing wrong.
To compute it in R you could do as follows:
firsts_of_months <- seq(as.Date("1901-01-01"), as.Date("2000-12-01"), by = "1 month")
sum(weekdays(firsts_of_months) == "Sonntag") # use == "sunday" or your local language
Qt 5.5 QDateTime::addSec function has returned a wrong value in a last day of a month if add 12 hours (43200 secs).
I's got the following result today 30 november 2015:
1.
QDateTime::currentDateTimeUtc().addSecs(43200);
output (run time - 2015-11-30T10:05:50):
date - Mon Nov 30 10:05:50 2015 GMT
2.
QDateTime::currentDateTimeUtc().addSecs(21600);
output (run time - 2015-11-30T10:08:12):
date - Mon Nov 30 16:08:12 2015 GMT
3.
QDateTime::currentDateTimeUtc().addDays(1).addSecs(-43200);
output (run time - 2015-11-30T10:11:08):
date - Tue Dec 1 10:11:08 2015 GMT
I want to add 12 hours and get 2015-11-30T22:11:08
How to avoid this situation? Is it a bug in Qt or I do something wrong?
Note that QDateTime QDateTime::addSecs(int s) const is a const function, that means, it does not change this object. You need to evaluate the returned object:
QDateTime dt = QDateTime::currentDateTimeUtc().addSecs(43200);
... output dt ...
Also from the latest documentation (Qt Documentation for version 4.8 did not have this):
Note that the time will wrap if it passes midnight.
Whatever this means...
I wrote a small example. And everything works as expected. I think It's environment issue. Thank you everyone!