Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
deploy-scripts.sh renamed to deploy-queries.sh
added generation of a new script: download-scripts.sh
gaarf-wf: functions/deploys.sh added --max-instances argument to pass to `gcloud functions deploy`
gaarf-wf: workflow: fixed default value for concurrency_limit (we have to pass a value in any case, so the default value of 20 was hard-coded)

Change-Id: I948d6eab2461a835ac6b6c6656e4d6f140db4657
  • Loading branch information
evil-shrike committed Oct 11, 2023
1 parent dcab3e6 commit a2ace98
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 23 deletions.
25 changes: 16 additions & 9 deletions gcp/create-gaarf-wf/build/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gcp/create-gaarf-wf/build/index.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions gcp/create-gaarf-wf/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion gcp/create-gaarf-wf/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "create-gaarf-wf",
"version": "1.8.2",
"version": "1.9.0",
"description": "Interactive generator for Gaarf (Google Ads API Report Fetcher) Workflow",
"type": "module",
"bin": {
Expand Down
29 changes: 20 additions & 9 deletions gcp/create-gaarf-wf/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ function get_macro_values(
console.log(
chalk.yellow('Tip: ') +
chalk.gray(
'besides constants you can use :YYYYMMDD-N values and expressions (${..})'
'you can use constants, :YYYYMMDD-N values (where N is a number) and expressions (${..})'
) +
'\n' +
chalk.yellow('Tip: ') +
Expand Down Expand Up @@ -558,7 +558,7 @@ async function initialize_googleads_config(answers: Partial<any>) {
chalk.yellow(
" does not exist, please note that you need to upload it before you can actually deploy and run, after that you'll need to run "
) +
chalk.cyan('deploy-scripts.sh')
chalk.cyan('deploy-queries.sh')
);
} else if (!fs.statSync(path_to_googleads_config).isFile()) {
console.log(
Expand Down Expand Up @@ -852,8 +852,8 @@ async function init() {
}
// Note that we deploy queries to hard-coded paths
deploy_shell_script(
'deploy-scripts.sh',
`# Deploy Ads and BQ scripts from local folders to Goggle Cloud Storage.
'deploy-queries.sh',
`# Deploy Ads and BQ queries from local folders to Google Cloud Storage.
GCS_BASE_PATH=${gcs_base_path}
gsutil -m cp ${path_to_googleads_config} $GCS_BASE_PATH/google-ads.yaml
Expand Down Expand Up @@ -1039,20 +1039,20 @@ fi
{
type: 'confirm',
name: 'deploy_scripts',
message: 'Do you want to deploy scripts (Ads/BQ) to GCS:',
message: 'Do you want to deploy queries (Ads/BQ) to GCS:',
default: true,
},
answers
)
).deploy_scripts
) {
const res = await exec_cmd(path.join(cwd, './deploy-scripts.sh'), null, {
const res = await exec_cmd(path.join(cwd, './deploy-queries.sh'), null, {
realtime: true,
});
if (res.code !== 0 && !ignore_errors) {
console.log(
chalk.red(
'Scripts deployment (deploy-scripts.sh) failed, breaking'
'Queries deployment (deploy-queries.sh) failed, breaking'
)
);
process.exit(res.code);
Expand All @@ -1061,7 +1061,7 @@ fi
} else {
console.log(
chalk.yellow(
"Please note that before you deploy queries to GCS (deploy-scripts.sh) there's no sense in running workflow (it'll fail)"
"Please note that before you deploy queries to GCS (deploy-queries.sh) you can't run the workflow (it'll fail)"
)
);
}
Expand Down Expand Up @@ -1126,6 +1126,7 @@ fi
{
type: 'confirm',
name: 'run_job',
default: false,
message: "Do you want to run the job right now (it's asynchronous):",
},
],
Expand Down Expand Up @@ -1282,6 +1283,16 @@ gcloud scheduler jobs create http $JOB_NAME \\
),
{silent: true}
);
// create download-script.sh shell script to download scripts back from GCS
deploy_shell_script(
'download-scripts.sh',
`for file in *.sh; do
[ -e "$file" ] || continue
cp -- "$file" "$\{file\}.bak"
done
gsutil -m cp ${gcs_base_path}/scripts/*.sh .`
);

console.log(
`All generated shell scripts were uploaded to GCS ${chalk.cyan(
gcs_base_path + '/scripts'
Expand All @@ -1293,7 +1304,7 @@ gcloud scheduler jobs create http $JOB_NAME \\
console.log(chalk.yellow('Tips for using the generated scripts:'));
console.log(
` 🔹 ${chalk.cyan(
'deploy-scripts.sh'
'deploy-queries.sh'
)} - redeploy queries and google-ads.yaml to GCS`
);
console.log(
Expand Down
6 changes: 6 additions & 0 deletions gcp/functions/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ FUNCTION_NAME=gaarf
REGION=us-central1
MEMORY=1024MB
RETRIES=5
MAX_INSTANCES=

while :; do
case $1 in
Expand All @@ -50,6 +51,10 @@ while :; do
shift
RETRIES=$1
;;
--max-instances)
shift
MAX_INSTANCES=--max-instances=$1
;;
*)
break
esac
Expand All @@ -72,6 +77,7 @@ function execute_deploy() {
--region=$REGION \
--quiet \
--gen2 \
$MAX_INSTANCES \
--source=.
echo $? > $statusfile
}
Expand Down
3 changes: 2 additions & 1 deletion gcp/workflow/workflows.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ main:
- gcs_bucket: ${default(map.get(args,"gcs_bucket"), project)}
- only_run_bq: ${default(map.get(args,"only_run_bq"), false)}
- completion_topic: ${default(map.get(args, "completion_topic"), "gaarf_wf_completed")}
- concurrency_limit: ${default(map.get(args, "concurrency_limit"), null)}
# 20 is the default for "Concurrent branches and iterations" - https://cloud.google.com/workflows/quotas#parallel_steps
- concurrency_limit: ${default(map.get(args, "concurrency_limit"), 20)}
- check_shortcut_arg:
switch:
- condition: ${only_run_bq}
Expand Down

0 comments on commit a2ace98

Please sign in to comment.