Skip to content

Commit 1da18c2

Browse files
Szpadelkrisdante
authored andcommitted
Implement custom crons
1 parent edeb578 commit 1da18c2

File tree

3 files changed

+49
-0
lines changed

3 files changed

+49
-0
lines changed

group_vars/all.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,6 +944,9 @@ magento_cron_http: "{{ not aws_use }}"
944944
aws_magento_cron_enabled: "{{ aws_use }}"
945945
magento_cron_observer_relative_path: vendor/magento/module-cron/Observer/ProcessCronQueueObserver.php
946946

947+
aws_magento_cron_crons_extra: []
948+
aws_magento_cron_crons_tpl: []
949+
aws_magento_cron_crons: "{{ (aws_magento_cron_crons_tpl | flatten) + aws_magento_cron_crons_extra }}"
947950

948951
# ----------------------------------
949952
# -------- Magento Deploy --------

roles/cs.aws-magento-cron/defaults/main.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,29 @@ aws_magento_cron_files_install:
88

99
aws_magento_cron_files_install_templated:
1010
- { src: "magento-cron-aws.service.j2", dest: "/etc/systemd/system/magento-cron-aws.service" }
11+
12+
# name - just for documentation purposes
13+
# only_cron_node - endure that this command is only executed when current node is elected as cron node
14+
# magento_command - execute in magento directory and as magento user, command will be executed as `bin/magento {command}`
15+
# user - execute as specific user, ignored when magento_command is set
16+
# command - depending on magento_command, this is either shell command or bin/magento argument
17+
#
18+
# Time can be set using following parameters, if not specified, defaults to *
19+
# month
20+
# weekday
21+
# day
22+
# hour
23+
# minute
24+
aws_magento_cron_crons:
25+
# - command: shell-command
26+
# name: Execute some shell command
27+
# only_cron_node: yes
28+
# magento_command: no
29+
# user: root
30+
# minute: */1
31+
32+
# - command: cron:extra:run
33+
# name: Execute magento command
34+
# only_cron_node: yes
35+
# magento_command: yes
36+
# minute: */1

roles/cs.aws-magento-cron/tasks/main.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,23 @@
4242
with_items: "{{ aws_magento_cron_files_install + aws_magento_cron_files_install_templated }}"
4343
when: aws_magento_cron_service_exists.stat.exists
4444
when: "not aws_magento_cron_enabled or magento_cron_disabled"
45+
46+
- name: Install crons
47+
cron:
48+
name: "{{ item.name }}"
49+
job: |
50+
{%- if item.only_cron_node -%}
51+
mageopscli is_cron_node &&
52+
{%- endif -%}
53+
{%- if item.magento_command -%}
54+
cd {{ magento_live_release_dir }} && bin/magento {{ item.command }}
55+
{%- else -%}
56+
{{ item.command }}
57+
{%- endif -%}
58+
user: "{{ item.magento_command | ternary(magento_user, item.user) }}"
59+
month: "{{ item.month | default(omit) }}"
60+
weekday: "{{ item.weekday | default(omit) }}"
61+
day: "{{ item.day | default(omit) }}"
62+
hour: "{{ item.hour | default(omit) }}"
63+
minute: "{{ item.minute | default(omit) }}"
64+
loop: "{{ aws_magento_cron_crons }}"

0 commit comments

Comments
 (0)