Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add firebase function and cron #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .firebaserc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"projects": {
"default": "dismoi-29127"
}
}
66 changes: 66 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
firebase-debug.log*
firebase-debug.*.log*

# Firebase cache
.firebase/

# Firebase config

# Uncomment this if you'd like others to create their own Firebase project.
# For a team working on the same Firebase project(s), it is recommended to leave
# it commented so all members can deploy to the same project(s) in .firebaserc.
# .firebaserc

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components

# node-waf configuration
.lock-wscript

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release

# Dependency directories
node_modules/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
20 changes: 20 additions & 0 deletions firebase.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"functions": {
"predeploy": [
"npm --prefix \"$RESOURCE_DIR\" run lint"
]
},
"emulators": {
"firestore": {
"port": 8080,
"host": "192.168.0.39"
},
"functions": {
"port": 5002,
"host": "192.168.0.39"
},
"ui": {
"enabled": true
}
}
}
18 changes: 18 additions & 0 deletions functions/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: {
es6: true,
node: true,
},
extends: [
"eslint:recommended",
"google",
],
rules: {
"quotes": ["error", "double"],
"require-jsdoc": 0,
},
parserOptions: {
"ecmaVersion": 8,
},
};
1 change: 1 addition & 0 deletions functions/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
25 changes: 25 additions & 0 deletions functions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const functions = require("firebase-functions");
const fetch = require("node-fetch");
const admin = require("firebase-admin");

async function scheduledFunctionCrontab() {
const res = await fetch("https://notices.bulles.fr/api/v3/matching-contexts");
const resJSON = await res.json();

if (admin.apps.length === 0) {
admin.initializeApp(functions.config().firebase);
}

const db = admin.firestore();

const docRef = db.collection("matchingContexts");

for (const matchingContext of resJSON) {
docRef.doc().set(matchingContext);
}
}

exports.scheduledFunctionCrontab = functions
.pubsub // .schedule("5 11 * * *")
.schedule("every 30 minutes")
.onRun(scheduledFunctionCrontab);
Loading