mirror of
https://github.com/status-im/open-bounty.git
synced 2025-02-28 17:10:38 +00:00
Add exception handling inside doseq in scheduler tasks
This commit is contained in:
parent
cd44e15969
commit
6fac1eee9a
@ -15,13 +15,16 @@
|
|||||||
[clj-time.periodic :refer [periodic-seq]]
|
[clj-time.periodic :refer [periodic-seq]]
|
||||||
[chime :refer [chime-at]]))
|
[chime :refer [chime-at]]))
|
||||||
|
|
||||||
|
|
||||||
(defn update-issue-contract-address
|
(defn update-issue-contract-address
|
||||||
"For each pending deployment: gets transaction receipt, updates db
|
"For each pending deployment: gets transaction receipt, updates db
|
||||||
state (contract-address, comment-id) and posts github comment"
|
state (contract-address, comment-id) and posts github comment"
|
||||||
[]
|
[]
|
||||||
|
(log/info "In update-issue-contract-address")
|
||||||
(doseq [{issue-id :issue_id
|
(doseq [{issue-id :issue_id
|
||||||
transaction-hash :transaction_hash} (issues/list-pending-deployments)]
|
transaction-hash :transaction_hash} (issues/list-pending-deployments)]
|
||||||
(log/debug "pending deployment:" transaction-hash)
|
(log/info "pending deployment:" transaction-hash)
|
||||||
|
(try
|
||||||
(when-let [receipt (eth/get-transaction-receipt transaction-hash)]
|
(when-let [receipt (eth/get-transaction-receipt transaction-hash)]
|
||||||
(log/info "update-issue-contract-address: transaction receipt for issue #"
|
(log/info "update-issue-contract-address: transaction receipt for issue #"
|
||||||
issue-id ": " receipt)
|
issue-id ": " receipt)
|
||||||
@ -51,7 +54,11 @@
|
|||||||
balance-eth
|
balance-eth
|
||||||
balance-eth-str
|
balance-eth-str
|
||||||
{}))
|
{}))
|
||||||
(log/error "Failed to find contract address in tx logs")))))
|
(log/error "Failed to find contract address in tx logs")))
|
||||||
|
(catch Throwable ex
|
||||||
|
(do (log/error "update-issue-contract-address exception:" ex)
|
||||||
|
(clojure.stacktrace/print-stack-trace ex)))))
|
||||||
|
(log/info "Exit update-issue-contract-address"))
|
||||||
|
|
||||||
|
|
||||||
(defn deploy-contract [owner-address issue-id]
|
(defn deploy-contract [owner-address issue-id]
|
||||||
@ -85,6 +92,7 @@
|
|||||||
(defn self-sign-bounty
|
(defn self-sign-bounty
|
||||||
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
|
"Walks through all issues eligible for bounty payout and signs corresponding transaction"
|
||||||
[]
|
[]
|
||||||
|
(log/info "In self-sign-bounty")
|
||||||
(doseq [{contract-address :contract_address
|
(doseq [{contract-address :contract_address
|
||||||
issue-id :issue_id
|
issue-id :issue_id
|
||||||
payout-address :payout_address
|
payout-address :payout_address
|
||||||
@ -94,8 +102,9 @@
|
|||||||
issue-number :issue_number
|
issue-number :issue_number
|
||||||
balance-eth :balance_eth
|
balance-eth :balance_eth
|
||||||
tokens :tokens
|
tokens :tokens
|
||||||
winner-login :winner_login} (db-bounties/pending-bounties)
|
winner-login :winner_login} (db-bounties/pending-bounties)]
|
||||||
:let [value (eth/get-balance-hex contract-address)]]
|
(try
|
||||||
|
(let [value (eth/get-balance-hex contract-address)]
|
||||||
(if (empty? payout-address)
|
(if (empty? payout-address)
|
||||||
(do
|
(do
|
||||||
(log/error "Cannot sign pending bounty - winner has no payout address")
|
(log/error "Cannot sign pending bounty - winner has no payout address")
|
||||||
@ -118,11 +127,17 @@
|
|||||||
(eth-decimal->str balance-eth)
|
(eth-decimal->str balance-eth)
|
||||||
tokens
|
tokens
|
||||||
winner-login
|
winner-login
|
||||||
false)))))
|
false))))
|
||||||
|
(catch Throwable ex
|
||||||
|
(do (log/error "self-sign-bounty exception:" ex)
|
||||||
|
(clojure.stacktrace/print-stack-trace ex)))))
|
||||||
|
(log/info "Exit self-sign-bounty")
|
||||||
|
)
|
||||||
|
|
||||||
(defn update-confirm-hash
|
(defn update-confirm-hash
|
||||||
"Gets transaction receipt for each pending payout and updates DB confirm_hash with tranaction ID of commiteth bot account's confirmation."
|
"Gets transaction receipt for each pending payout and updates DB confirm_hash with tranaction ID of commiteth bot account's confirmation."
|
||||||
[]
|
[]
|
||||||
|
(log/info "In update-confirm-hash")
|
||||||
(doseq [{issue-id :issue_id
|
(doseq [{issue-id :issue_id
|
||||||
execute-hash :execute_hash} (db-bounties/pending-payouts)]
|
execute-hash :execute_hash} (db-bounties/pending-payouts)]
|
||||||
(log/info "pending payout:" execute-hash)
|
(log/info "pending payout:" execute-hash)
|
||||||
@ -130,7 +145,8 @@
|
|||||||
(log/info "execution receipt for issue #" issue-id ": " receipt)
|
(log/info "execution receipt for issue #" issue-id ": " receipt)
|
||||||
(when-let [confirm-hash (multisig/find-confirmation-tx-id receipt)]
|
(when-let [confirm-hash (multisig/find-confirmation-tx-id receipt)]
|
||||||
(log/info "confirm hash:" confirm-hash)
|
(log/info "confirm hash:" confirm-hash)
|
||||||
(db-bounties/update-confirm-hash issue-id confirm-hash)))))
|
(db-bounties/update-confirm-hash issue-id confirm-hash))))
|
||||||
|
(log/info "Exit update-confirm-hash"))
|
||||||
|
|
||||||
|
|
||||||
(defn update-watch-hash
|
(defn update-watch-hash
|
||||||
@ -154,6 +170,7 @@
|
|||||||
(defn update-payout-receipt
|
(defn update-payout-receipt
|
||||||
"Gets transaction receipt for each confirmed payout and updates payout_hash"
|
"Gets transaction receipt for each confirmed payout and updates payout_hash"
|
||||||
[]
|
[]
|
||||||
|
(log/info "In update-payout-receipt")
|
||||||
(doseq [{issue-id :issue_id
|
(doseq [{issue-id :issue_id
|
||||||
payout-hash :payout_hash
|
payout-hash :payout_hash
|
||||||
contract-address :contract_address
|
contract-address :contract_address
|
||||||
@ -167,6 +184,7 @@
|
|||||||
payee-login :payee_login
|
payee-login :payee_login
|
||||||
updated :updated} (db-bounties/confirmed-payouts)]
|
updated :updated} (db-bounties/confirmed-payouts)]
|
||||||
(log/debug "confirmed payout:" payout-hash)
|
(log/debug "confirmed payout:" payout-hash)
|
||||||
|
(try
|
||||||
(if-let [receipt (eth/get-transaction-receipt payout-hash)]
|
(if-let [receipt (eth/get-transaction-receipt payout-hash)]
|
||||||
(let [contract-tokens (multisig/token-balances contract-address)
|
(let [contract-tokens (multisig/token-balances contract-address)
|
||||||
contract-eth-balance (eth/get-balance-wei contract-address)]
|
contract-eth-balance (eth/get-balance-wei contract-address)]
|
||||||
@ -192,7 +210,12 @@
|
|||||||
payee-login))))
|
payee-login))))
|
||||||
(when (older-than-3h? updated)
|
(when (older-than-3h? updated)
|
||||||
(log/info "Resetting payout hash for issue" issue-id "as it has not been mined in 3h")
|
(log/info "Resetting payout hash for issue" issue-id "as it has not been mined in 3h")
|
||||||
(db-bounties/reset-payout-hash issue-id)))))
|
(db-bounties/reset-payout-hash issue-id)))
|
||||||
|
(catch Throwable ex
|
||||||
|
(do (log/error "update-payout-receipt exception:" ex)
|
||||||
|
(clojure.stacktrace/print-stack-trace ex)))))
|
||||||
|
(log/info "Exit update-payout-receipt")
|
||||||
|
)
|
||||||
|
|
||||||
(defn abs
|
(defn abs
|
||||||
"(abs n) is the absolute value of n"
|
"(abs n) is the absolute value of n"
|
||||||
@ -213,17 +236,24 @@
|
|||||||
(defn update-bounty-token-balances
|
(defn update-bounty-token-balances
|
||||||
"Helper function for updating internal ERC20 token balances to token multisig contract. Will be called periodically for all open bounty contracts."
|
"Helper function for updating internal ERC20 token balances to token multisig contract. Will be called periodically for all open bounty contracts."
|
||||||
[issue-id bounty-addr watch-hash]
|
[issue-id bounty-addr watch-hash]
|
||||||
|
(log/info "In update-bounty-token-balances for issue" issue-id)
|
||||||
(doseq [[tla token-data] (token-data/as-map)]
|
(doseq [[tla token-data] (token-data/as-map)]
|
||||||
|
(try
|
||||||
(let [balance (multisig/token-balance bounty-addr tla)]
|
(let [balance (multisig/token-balance bounty-addr tla)]
|
||||||
(when (> balance 0)
|
(when (> balance 0)
|
||||||
(do
|
(do
|
||||||
(log/debug "bounty at" bounty-addr "has" balance "of token" tla)
|
(log/info "bounty at" bounty-addr "has" balance "of token" tla)
|
||||||
(let [internal-balance (multisig/token-balance-in-bounty bounty-addr tla)]
|
(let [internal-balance (multisig/token-balance-in-bounty bounty-addr tla)]
|
||||||
(when (and (nil? watch-hash)
|
(when (and (nil? watch-hash)
|
||||||
(not= balance internal-balance))
|
(not= balance internal-balance))
|
||||||
(log/info "balances not in sync, calling watch")
|
(log/info "balances not in sync, calling watch")
|
||||||
(let [hash (multisig/watch-token bounty-addr tla)]
|
(let [hash (multisig/watch-token bounty-addr tla)]
|
||||||
(db-bounties/update-watch-hash issue-id hash)))))))))
|
(db-bounties/update-watch-hash issue-id hash)))))))
|
||||||
|
(catch Throwable ex
|
||||||
|
(do (log/error "update-bounty-token-balances exception:" ex)
|
||||||
|
(clojure.stacktrace/print-stack-trace ex)))))
|
||||||
|
(log/info "Exit update-bounty-token-balances"))
|
||||||
|
|
||||||
|
|
||||||
(defn update-contract-internal-balances
|
(defn update-contract-internal-balances
|
||||||
"It is required in our current smart contract to manually update it's internal balance when some tokens have been added."
|
"It is required in our current smart contract to manually update it's internal balance when some tokens have been added."
|
||||||
@ -263,6 +293,7 @@
|
|||||||
|
|
||||||
(defn update-balances
|
(defn update-balances
|
||||||
[]
|
[]
|
||||||
|
(log/info "In update-balances")
|
||||||
(doseq [{contract-address :contract_address
|
(doseq [{contract-address :contract_address
|
||||||
owner :owner
|
owner :owner
|
||||||
repo :repo
|
repo :repo
|
||||||
@ -271,6 +302,7 @@
|
|||||||
db-balance-eth :balance_eth
|
db-balance-eth :balance_eth
|
||||||
db-tokens :tokens
|
db-tokens :tokens
|
||||||
issue-number :issue_number} (db-bounties/open-bounty-contracts)]
|
issue-number :issue_number} (db-bounties/open-bounty-contracts)]
|
||||||
|
(try
|
||||||
(when comment-id
|
(when comment-id
|
||||||
(let [balance-eth-str (eth/get-balance-eth contract-address 6)
|
(let [balance-eth-str (eth/get-balance-eth contract-address 6)
|
||||||
balance-eth (read-string balance-eth-str)
|
balance-eth (read-string balance-eth-str)
|
||||||
@ -307,7 +339,11 @@
|
|||||||
balance-eth
|
balance-eth
|
||||||
balance-eth-str
|
balance-eth-str
|
||||||
token-balances)
|
token-balances)
|
||||||
(update-issue-usd-value contract-address))))))
|
(update-issue-usd-value contract-address))))
|
||||||
|
(catch Throwable ex
|
||||||
|
(do (log/error "update-balances exception:" ex)
|
||||||
|
(clojure.stacktrace/print-stack-trace ex)))))
|
||||||
|
(log/info "Exit update-balances"))
|
||||||
|
|
||||||
|
|
||||||
(defn wrap-in-try-catch [func]
|
(defn wrap-in-try-catch [func]
|
||||||
@ -323,7 +359,7 @@
|
|||||||
|
|
||||||
(defn run-1-min-interval-tasks [time]
|
(defn run-1-min-interval-tasks [time]
|
||||||
(do
|
(do
|
||||||
(log/debug "run-1-min-interval-tasks" time)
|
(log/info "run-1-min-interval-tasks" time)
|
||||||
;; TODO: disabled for now. looks like it may cause extraneus
|
;; TODO: disabled for now. looks like it may cause extraneus
|
||||||
;; contract deployments and costs
|
;; contract deployments and costs
|
||||||
(run-tasks
|
(run-tasks
|
||||||
|
Loading…
x
Reference in New Issue
Block a user